简体   繁体   English

使用qmake / Qt Creator链接调试/发布库

[英]Linking with a debug/release lib with qmake/Qt Creator

I am using Qt Creator and have a Qt GUI project that depends on a C++ static library project. 我正在使用Qt Creator并拥有一个依赖于C ++静态库项目的Qt GUI项目。 I want to link the release version of the GUI app with the release build of the .lib and the debug release of the GUI app with the debug .lib. 我想将GUI应用程序的发布版本与.lib的发布版本以及带有调试.lib的GUI应用程序的调试版本链接起来。 I have found out how to add additional libraries to the project by including a line like the following in my .pro file: 我已经找到了如何通过在我的.pro文件中包含如下所示的行来向项目中添加其他库:

LIBS += -L./libfolder -lmylib.lib

But I cannot see how I can use a different -L command for release and debug builds. 但我无法看到如何使用不同的-L命令进行发布和调试构建。

Is there support in qmake to do this? qmake是否有支持这样做?

The normal 正常

debug:LIBS += ...
else:LIBS += ...

solution breaks when users naively use CONFIG += debug or CONFIG += release to switch between debug and release builds (and they do; no-one remembers to say CONFIG -= release release_and_debug before CONFIG += debug :). 当用户天真地使用CONFIG += debugCONFIG += release来在调试和发布版本之间切换时,解决方案会中断(他们会这样做;没有人记得在CONFIG += debug :)之前说CONFIG -= release release_and_debug

This is the canonical way to scope on debug : 这是debug范围的规范方法:

CONFIG( debug, debug|release ) {
    # debug
    QMAKE_LIBDIR += "path/to/debug/lib"
} else {
    # release
    QMAKE_LIBDIR += "path/to/release/lib"
}

Cf. 参看 the qmake docs . qmake文档

EDIT 2013-11-17 : Don't use -Lfoo in LIBS . 编辑2013-11-17 :不要在LIBS使用-Lfoo The canonical way is to add the paths (without the -L ) to QMAKE_LIBDIR . 规范的方法是将路径(不带-L )添加到QMAKE_LIBDIR

In your project file you can do something like this 在您的项目文件中,您可以执行以下操作

debug {
    LIBS += -L./libfolder -lmydebuglib.lib
}

release {
    LIBS += -L./libfolder -lmyreleaselib.lib
}

The bit inside the debug braces is used if DEBUG has been added to the CONFIG qmake variable, similarly stuff inside the release brackets is included if RELEASE has been added to the CONFIG variable. 如果已将DEBUG添加到CONFIG qmake变量,则使用调试大括号内的位,如果将RELEASE添加到CONFIG变量,则类似于释放括号内的内容。

You can also use "!debug" rather than "release" (ie when debug isn't in the config) 您也可以使用“!debug”而不是“release”(即当调试不在配置中时)

You can find more information on qmake here . 您可以在此处找到有关qmake的更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM