I am a newbie with in Qt & started appreciating the framework that qmake provides in .pro files. Primary objective of my question is to understand in detail the difference between qmake variables "LIBS" & "PRE_TARGETDEPS" with static linking of libraries.
My Qt App uses a bunch of C++ static libraries that it depends on. Again, the static libraries have interdependencies between themselves. Each library has a .pro file included in it to support qmake way of building. And of course the app also has a .pro file.
Now in the static libraries, if libStaticA is dependent on libStaticB where both are C++ libraries. And both of them have a .pro file each. Is it enough to mention the dependency in libStaticA.pro with +LIBS & -l like below ? +LIBS += -L/path_To_libStaticB/ -llibStaticB
Or is it enough to mention the dependency with PRE_TARGETDEPS like below +PRE_TARGETDEPS += /path_To_libStaticB/libStaticB.a
Or should I mention both ? +PRE_TARGETDEPS += /path_To_libStaticB/libStaticB.a +LIBS += /path_To_libStaticB/libStaticB.a
What is the relevance of LIBS & PRE_TARGETDEPS ?
PS: My development machine is osx. Thanks in advance for any explanations to clarify my understanding here
答案 0 :(得分:5)
LIBS
:
指定要链接到项目的库列表。如果使用Unix -l(库)和-L(库路径)标志,qmake会在Windows上正确处理库(即,将库的完整路径传递给链接器)。 qmake必须存在库才能找到-l lib所在的目录。
PRE_TARGETDEPS
:
列出目标所依赖的库。某些后端(如Visual Studio和Xcode项目文件的生成器)不支持此变量。通常,这些构建工具在内部支持此变量,它对于显式列出依赖的静态库非常有用。
Qt使用PRE_TARGETDEPS
变量来存储静态链接库的依赖项。每次构建应用程序时,它都会强制您的库重新链接。
如果您没有指定此变量并且更新并重建库,则您的程序仍将使用旧库。
对于您的问题,如果您使用静态库,您应该(几乎)始终同时使用LIB
和PRE_TARGETDEPS
。
引用:Qmake variable reference
同样有趣:Adding libraries to Qt Projects