GCC and ld cannot find exported characters ... but they are!

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

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

The classes in the library seem to be very well versed in the linker, but free functions and exported data (such as the cosine lookup table) invariably lead to the above error.

I use Ubuntu 8.04 (Hardy) and it is updated with the latest Unbuntu packages.

The command to link the library (with the removal of other libraries):

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

The command to connect the application (with the removal of other libraries):

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

Finally, it appears (as far as I can tell) that the corresponding characters are exported correctly:

nm -D ~/project/lib/release/lib-in-question.so | grep GetStatusStr --> U _ZN3lib-namespace12GetStatusStrEi
+3
source share
2 answers

U before _ZN3lib-namespace12GetStatusStrEi in nm output indicates that the character is undefined in the library.

It may be defined in the wrong namespace: it looks like you are calling it in lib-namespace, but you can define it in another.

+8
source

It has been a while, but if you specify lib with the -l option, then don't you have the lib prefix?

(I changed the name from "lib-in-question.so" to "libfoobar.so" for easier reading for the example below)

g++ -fPIC -Wall -O3  -L~/project/lib/release -lfoobar

or

g++ -fPIC -Wall -O3  ~/project/lib/release/libfoobar.so
+2
source

All Articles