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.