3

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
Jason Aller
  • 3,541
  • 28
  • 38
  • 38
Clay
  • 1,159
  • 1
  • 9
  • 20
  • You are not giving us enough information; consequently you will be getting a lot of wrong guesses. You probably just made a simple mistake. Simplify the code needed to reproduce the error to a minimum. Then post it along with the actual shell commands, and their output, which lead to the error. – ejgottl Oct 19 '08 at 14:56
  • "lib-namespace" is not a legal namespace, what's the actual symbol name? – Alex B Oct 20 '08 at 00:56

2 Answers2

8

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.

PiedPiper
  • 5,735
  • 1
  • 30
  • 40
2

It's been a while, but if you specify a lib with the -l option, then don't you have the skip 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
Christian.K
  • 47,778
  • 10
  • 99
  • 143
  • My makefile has that bit right: the library is libzclocksupport but the linker command is -lzclocksupport – Clay Oct 19 '08 at 15:51