目的
了解pro 文件配置中关于 LIBS 与 PRE_TARGETDEPS 区别
区别
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.
形式:
LIBS += -L$$OUT_PWD/../common -lcommon
目的:
指定要链接到项目中的库列表。
如果您使用 Unix -l(库)和 -L(库路径)标志,qmake 在 Windows 上正确处理库(即,将库的完整路径传递给链接器)。该库必须存在,qmake 才能找到 -l lib 所在的目录。
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.
形式:
PRE_TARGETDEPS+= $$OUT_PWD/../common/libcommon.a
目的:
列出目标所依赖的库。
某些后端(例如 Visual Studio 和 Xcode 项目文件的生成器)不支持此变量。通常,这些构建工具在内部支持此变量,它对于显式列出依赖的静态库很有用。
主要区别
Qt 使用 PRE_TARGETDEPS 变量来存储静态链接库的依赖关系。每次构建应用程序时,它都会强制您的库重新链接。
如果您没有指定此变量并且您更新和重建您的库,您的程序仍将使用旧库。
如果您使用静态库,您应该(几乎)始终同时使用 LIB 和 PRE_TARGETDEPS.