Skip to content
Advertisement

GCC and ld can’t find exported symbols…but they’re there

I have a C++ library and a C++ application trying to use functions and classes exported from the library. The library builds fine and the application compiles but fails to link. The errors I get follow this form:

app-source-file.cpp:(.text+0x2fdb): undefined reference to `lib-namespace::GetStatusStr(int)’

Classes in the library seem to be resolved just fine by the linker, but free functions and exported data (like a cosine lookup table) invariably result in the above error.

I am using Ubuntu 8.04 (Hardy), and it is up to date with the latest Ubuntu packages.

The command to link the library is (with other libraries removed):

g++ -fPIC -Wall -O3 -shared -Wl,-soname,lib-in-question.so -o ~/project/lib/release/lib-in-question.so

The command to link the application is (with other libraries removed):

g++ -fPIC -Wall -O3  -L~/project/lib/release -llib-in-question -o ~/project/release/app-in-question

Finally, it appears (as best as I can tell) that the symbols in question are being exported properly:

nm -D ~/project/lib/release/lib-in-question.so | grep GetStatusStr --> U _ZN3lib-namespace12GetStatusStrEi

Advertisement

Answer

the U before _ZN3lib-namespace12GetStatusStrEi in the nm output shows that the symbol is undefined in the library.

Maybe it’s defined in the wrong namespace: it looks like you’re calling it in lib-namepace but you might be defining it in another.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement