C++ 使用 qmake/Qt Creator 与调试/发布库链接
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1130106/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Linking with a debug/release lib with qmake/Qt Creator
提问by Rob
I am using Qt Creator and have a Qt GUI project that depends on a C++ static library project. 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. I have found out how to add additional libraries to the project by including a line like the following in my .pro file:
我正在使用 Qt Creator 并且有一个依赖于 C++ 静态库项目的 Qt GUI 项目。我想将 GUI 应用程序的发布版本与 .lib 的发布版本和 GUI 应用程序的调试版本与调试 .lib 链接起来。我已经找到了如何通过在我的 .pro 文件中包含如下一行来向项目添加其他库:
LIBS += -L./libfolder -lmylib.lib
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 是否支持这样做?
采纳答案by Nick
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" (i.e. when debug isn't in the config)
您还可以使用“!调试”而不是“发布”(即当调试不在配置中时)
You can find more information on qmake here.
您可以在此处找到有关 qmake 的更多信息。
回答by Marc Mutz - mmutz
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 += debug
或CONFIG += release
在调试和发布版本之间切换时,解决方案就会中断(他们确实这样做了;没有人记得CONFIG -= release release_and_debug
之前说过CONFIG += 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
. The canonical way is to add the paths (without the -L
) to QMAKE_LIBDIR
.
编辑 2013-11-17:不要-Lfoo
在LIBS
. 规范的方法是将路径(不带-L
)添加到QMAKE_LIBDIR
.