Linking external static library in Qt creator - executable keeps trying to find .so
-
I made a Qt Project with two sub-projects. One is a static library, the other is the GUI app that uses the static library.
Since this is a sub-project project I have specified the order in which the two parts are built. Starting with the static library in the project tree and then the app in the project tree. Done with the CONFIG+=ordered option.
I also require a third external static library. Which is in a separate directory on my system. This library can be used statically or dynamically.
Normally to use this third external library with g++ you'd do:
@g++ biohello.cpp
-o biohello
--static
-I$bpp_dir/include
-L$bpp_dir/lib
-lbpp-seq -lbpp-core
strip biohello@for static compilation or for dynamic:
@g++ biohello.cpp
-o biohello
-I$bpp_dir/include
-L$bpp_dir/lib
-lbpp-seq -lbpp-core@I'd like to include the library statically.
I've tried using the add library wizard of Creator which resulted in the addition of:
@win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../local/bpp/dev/lib/release/ -lbpp-seq
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../local/bpp/dev/lib/debug/ -lbpp-seq
else:unix: LIBS += -L$$PWD/../../local/bpp/dev/lib/ -lbpp-seqINCLUDEPATH += $$PWD/../../local/bpp/dev/include
DEPENDPATH += $$PWD/../../local/bpp/dev/includewin32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/../../local/bpp/dev/lib/release/libbpp-seq.a
else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/../../local/bpp/dev/lib/debug/libbpp-seq.a
else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/../../local/bpp/dev/lib/release/bpp-seq.lib
else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/../../local/bpp/dev/lib/debug/bpp-seq.lib
else:unix: PRE_TARGETDEPS += $$PWD/../../local/bpp/dev/lib/libbpp-seq.awin32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../local/bpp/dev/lib/release/ -lbpp-core
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../local/bpp/dev/lib/debug/ -lbpp-core
else:unix: LIBS += -L$$PWD/../../local/bpp/dev/lib/ -lbpp-coreINCLUDEPATH += $$PWD/../../local/bpp/dev/include
DEPENDPATH += $$PWD/../../local/bpp/dev/includewin32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/../../local/bpp/dev/lib/release/libbpp-core.a
else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/../../local/bpp/dev/lib/debug/libbpp-core.a
else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/../../local/bpp/dev/lib/release/bpp-core.lib
else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/../../local/bpp/dev/lib/debug/bpp-core.lib
else:unix: PRE_TARGETDEPS += $$PWD/../../local/bpp/dev/lib/libbpp-core.a@To the .pro files, hitting run makes the app run fine, but when I leave Creator and try to start the executable from my desktop or command line I'm told:
@error while loading shared libraries: libbpp-seq.so.9: cannot open shared object file: No such file or directory@
I haven't - to my knowlege, tried to include any shared objects, what I'm looking to do is include the external library statically using Qt Creator to the same result as you would with the g++ snippet above.
Thanks,
Ben W. -
Hi and welcome to devnet,
I guess you have both shared and static libraries in the same folder ? If so, and if IIRC the linker takes the shared library by default.
There you have several options, have both version in separated folder or change the link lines to the full path of your static libraries rather than the library name.
Hope it helps
-
Aaah yes they are in the same folder! Thank you, I'll try and be explicit in my link lines.
-
If I make the lines explicit I guess I have to change it to something like this?
From:
@win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../local/bpp/dev/lib/release/ -lbpp-seq
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../local/bpp/dev/lib/debug/ -lbpp-seq
else:unix: LIBS += -L$$PWD/../../local/bpp/dev/lib/ -lbpp-seq@To:
@win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../local/bpp/dev/lib/release/libbpp-seq.lib
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../local/bpp/dev/lib/debug/libbpp-seq.lib
else:unix: LIBS += -L$$PWD/../../local/bpp/dev/lib/libbpp-seq.a@I guess the last line applies to unix and osx so should be .a files and the others being windows would be .lib files? (I'm doing this on Ubuntu and haven't really done any coding on Windows before)
-
Ok I just decided to make everything easier and take the .so's out of the same folder. Deleted the stuff in the .pro file before and now there is
@unix|win32: LIBS += -L$$PWD/../../local/bpp/dev/lib/ -lbpp-seqINCLUDEPATH += $$PWD/../../local/bpp/dev/include
DEPENDPATH += $$PWD/../../local/bpp/dev/includewin32:!win32-g++ PRE_TARGETDEPS += $$PWD/../../local/bpp/dev/lib/bpp-seq.lib
else:unix|win32-g++: PRE_TARGETDEPS += $$PWD/../../local/bpp/dev/lib/libbpp-seq.aunix|win32: LIBS += -L$$PWD/../../local/bpp/dev/lib/ -lbpp-core
INCLUDEPATH += $$PWD/../../local/bpp/dev/include
DEPENDPATH += $$PWD/../../local/bpp/dev/includewin32:!win32-g++ PRE_TARGETDEPS += $$PWD/../../local/bpp/dev/lib/bpp-core.lib
else:unix|win32-g++: PRE_TARGETDEPS += $$PWD/../../local/bpp/dev/lib/libbpp-core.a@However trying to run results in a message:
Assignment needs exactly one word on the left hand side.
for the two lines:
@win32:!win32-g++ PRE_TARGETDEPS += $$PWD/../../local/bpp/dev/lib/bpp-seq.lib@
and
@win32:!win32-g++ PRE_TARGETDEPS += $$PWD/../../local/bpp/dev/lib/bpp-core.lib@
These are automatically generated by creator. I'm not sure why it thinks there are two words on the lhs of the assignment, since win32:!win32-g++ to mee looks like some logical condition for the build (I'm very new so might be wrong) and the variable corresponding to the lhs of the assignment is PRE_TARGETDEPS which seems like one word to me.
-
That's why
@win32:!win32-g++@
You need
@win32:!win32-g++:@