TheEagle
TheEagle

Reputation: 5982

symbols not found in static library even though they are there

I am trying to build TerraGear from the FlightGear project, and it needs multiple symbols from a static library libSimGearBucket upon linking, for example SGBucket::gen_base_path. ld fails with

warning: undefined reference to »SGBucket::gen_base_path[abi:cxx11]() const

These are defined in the library:

$ nm libSimGearCore.a | grep gen_base_path
00000000000001f0 T _ZNK8SGBucket13gen_base_pathEv
                 U _ZNK8SGBucket13gen_base_pathEv
                 U _ZNK8SGBucket13gen_base_pathEv

I made triple sure that library is linked to the program needing the symbols. What is wrong ?

Upvotes: 3

Views: 1975

Answers (2)

Peter Lamberg
Peter Lamberg

Reputation: 8651

Very likely not the same situation, but just mentioning here because this was one of the google hits when I was trying to solve my problem.

My similar problem went away when I switched to the LLVM linker LLD.

Maybe this will help someone with same kind of problem.

Upvotes: 1

Employed Russian
Employed Russian

Reputation: 213957

The function you need is SGBucket::gen_base_path[abi:cxx11]() const.

The function you have is SGBucket::gen_base_path() const. These aren't the same symbol.

You can use -Wl,--no-demangle at link time to tell the linker to print mangled (real) symbol that ends up undefined, and that would make it clearer that you don't in fact have a definition of that symbol.

Possibly the libSimGearCore.a library was compiled without -std=c++11 flag, while the code which needs the symbol was compiled with it.

Upvotes: 2

Related Questions