I am creating an application, which consists of two static libs and an executable.
Let's call the two static libs: libusefulclass.a libcore.a
And the application: myapp
libcore instantiates and uses the class defined in libusefulclass (let's call it UsefulClass)
Now, if I link the application in the following way:
g++ -m64 -Wl,-rpath,/usr/local/Trolltech/Qt-4.5.4/lib -o myapp src1.o src2.o srcN.o -lusefulclass -lcore
The linker complains about the methods in libusefulclass not being found:
undefined reference to `开发者_C百科UsefulClass::foo()'
etc.
I found a workaround for this: If UsefulClass is also instantiated within the source files of the executable itself, the application is linked without any problems.
My question is: is there a more clean way to make libcore refer to methods defined in libusefulclass, or static libs just cannot be linked against eachother?
TIA
P.S.: In case that matters: the application is being developed in C++ using Qt, but I feel this is not a Qt problem, but a library problem in general.
You need to specify the libraries in reverse order of dependencies, so use
g++ -m64 -Wl,-rpath,/usr/local/Trolltech/Qt-4.5.4/lib -o myapp src1.o src2.o srcN.o -lcore -lusefulclass
If there's a cyclic dependency, you might even need to specify the library twice,
g++ -m64 -Wl,-rpath,/usr/local/Trolltech/Qt-4.5.4/lib -o myapp src1.o src2.o srcN.o -lusefulclass -lcore -lusefulclass
精彩评论