其他分享
首页 > 其他分享> > c – Qt的.pro文件中的LIBS与PRE_TARGETDEPS

c – Qt的.pro文件中的LIBS与PRE_TARGETDEPS

作者:互联网

我是Qt&的新手开始欣赏qmake在.pro文件中提供的框架.
我的问题的主要目的是详细了解qmake变量“LIBS”和&之间的区别.带有静态链接库的“PRE_TARGETDEPS”.

我的Qt App使用了一堆依赖的C静态库.同样,静态库之间也存在相互依赖关系.每个库都包含一个.pro文件,以支持qmake构建方式.当然,该应用程序还有一个.pro文件.

现在在静态库中,如果libStaticA依赖于libStaticB,那么它们都是C库.它们都有一个.pro文件.
是否足以在libStaticA.pro中提及LIBS& amp; -l喜欢下面?
 LIBS = -L / path_To_libStaticB / -llibStaticB

或者就像下面提到PRE_TARGETDEPS的依赖性一样
 PRE_TARGETDEPS = /path_To_libStaticB/libStaticB.a

或者我应该提两个?
 PRE_TARGETDEPS = /path_To_libStaticB/libStaticB.a
 LIBS = /path_To_libStaticB/libStaticB.a

LIBS& amp;的相关性是什么? PRE_TARGETDEPS?

PS:我的开发机器是osx.
在此先感谢任何解释,以澄清我的理解

解决方法:

LIBS:

Specifies a list of libraries to be linked into the project. If you use the Unix -l (library) and -L (library path) flags, qmake handles the libraries correctly on Windows (that is, passes the full path of the library to the linker). The library must exist for qmake to find the directory where a -l lib is located.

PRE_TARGETDEPS:

Lists libraries that the target depends on. Some backends, such as the generators for Visual Studio and Xcode project files, do not support this variable. Generally, this variable is supported internally by these build tools, and it is useful for explicitly listing dependent static libraries.

Qt使用PRE_TARGETDEPS变量来存储静态链接库的依赖项.每次构建应用程序时,它都会强制您的库重新链接.
如果您没有指定此变量并且更新并重建库,则程序仍将使用旧库.

对于您的问题,如果您使用静态库,您应该(几乎)始终使用LIB和PRE_TARGETDEPS.

Quote:Qmake variable reference
同样有趣:Adding libraries to Qt Projects

标签:c,macos,qt,static-linking,qmake
来源: https://codeday.me/bug/20190829/1757719.html