0

I am only asking this as a last resort, it's been days that I have been trying to fix this linker problem and I have tried so many solutions found at stackoverflow that I have lost count.

Basically, I am trying to use the constuctor from a class included in a shared library. Let's call it LibraryClass(string) and let's call this library liblibrary.so.

Ok, so I am trying to use this constructor in a class called DummyClass and then compiling this one and lots of other DummyClasses and then compiling the objects into a single executable

I am using SCons btw, so it first compiles all the DummyClasses without including any library

g++ -o DummyClass.o  -I.... -I.... .... DummyClass.cpp
g++ -o DummyClass2.o -I.... -I.... .... DummyClass2.cpp

Then it compiles into a final executable linking the necessary libraries

g++ -o executable DummyClass.o DummyClass2.o -L/path/to/libs -llibrary -ldependency

Also, the library depends on functions from another library, let's call it libdependency.so

After compiling the executable, it gives me an undefined reference to LibraryClass(string) in DummyClass.o : DummyClass.cpp line ...

It's a big project and there are lots of other libraries involved and lots of other classes being compiled into the 'executable'

First, I've tried to verify that the function is indeed included in the library so i tried to use nm -C liblibrary.so and I can indeed see the function on the output. However if I try to use nm -CD liblibrary.so I cannot find the function in there (I don't know why but some answers at stack overflow used -CD others used -C)

It doesn't make sense, it should work, first it compiles all the classes, then it compiles the objects with undefined references into a single executable linking with all the required libraries.

What else can I check for?

About the possible duplicate of another question. I believe my question is unique since it is been shown that it might be a problem with the library itself, the question that has been marked as a possible duplicate doesn't mention my probable solution. I do believe my question might help others in the future since I have been looking for answers on stackoverflow for a whole week.

John Doe
  • 1
  • 1
  • When you did `nm -C liblibrary.so`, what was the single letter at the left of the function in question? For a defined function, you would usually see "`T`". But if it's "`U`", that means it's not actually in the library, but the library requires it just like DummyClass.o does. – aschepler Sep 24 '17 at 20:33
  • Possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – user0042 Sep 24 '17 at 20:34
  • It was a 't' character – John Doe Sep 24 '17 at 20:35
  • A lowercase "`t`" means the symbol has internal linkage, not external linkage, so no other object file can actually use it. Maybe you have a `static` keyword where you shouldn't? – aschepler Sep 24 '17 at 20:37
  • Hmm, so a problem inside the library or maybe on the compilation of the library? I will investigate this tomorrow at work and will post my findings. Thank you for giving me a place to investigate again! – John Doe Sep 24 '17 at 20:57

0 Answers0