如何检测Qt Creator的目标(调试/发布)(Visual Studio)

How to detect Qt Creator's target (debug/release) (Visual Studio)

本文关键字:调试 Visual Studio 目标 发布 Creator 何检测 检测 Qt      更新时间:2023-10-16

所以我使用qmake来创建我的程序,但是我总是在我的调试和发布boost库之间有冲突,消息:

libboost_system-vc120-mt-s-1_58.lib(error_code.obj):-1: error: LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in main.obj

我想使这个自动化,以这样一种方式,选择调试或从Qt Creator发布足以创建正确的版本。我看到过其他类似的解,但这行不通。当调用以下命令进行调试和发布时,可以看到它不起作用的原因:

message($$CONFIG)

将打印qmake的配置。结果如下:

发布的

:

lex yacc调试异常depend_includepath testcase_targets import_plugins import_qpa_plugin rtti_off incremental_off Windows qt warn_on release link_prl增量flat precompile_header autogen_precompile_source debug_and_release debug_and_release_target embed_manifest_dll embed_manifest_exe c++ ++11 debug static rtti no_plugin_manifest qpa win32 MSVC copy_dir_files release

调试:

lex yacc调试异常depend_includepath testcase_targets import_plugins import_qpa_plugin rtti_off incremental_off Windows qt warn_on release link_prl增量flat precompile_header autogen_precompile_source debug_and_release debug_and_release_target embed_manifest_dll embed_manifest_exe c++ ++11调试静态rtti no_plugin_manifest qpa win32 MSVC copy_dir_files

注意都包含debug和release…我想知道为什么…

我想指出我从源代码编译了这个Qt版本。但我这么做的时候并没有什么奇怪的事情。我使用以下命令来编译它(使用简单的nmake配置然后编译):

configure -debug-and-release -opensource -platform win32-msvc2013 -opengl desktop -static -nomake examples -nomake tests

我尝试了一个沉闷的解决方案,通过在我的make文件中添加命令:debug:CONFIG-=release,但是当我选择从Qt Creator发布时,这会导致发布版本成为30mb大小的调试而不是14mb。

我的qmake文件就是一个典型的例子。以下是可能与这个问题有关的部分。其他部分只是添加文件、库和路径:

QMAKE_CFLAGS += /MT
QT       += core gui
unix:QMAKE_CXXFLAGS += -std=c++11
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = MyProg
TEMPLATE = app

那么为什么会发生这个问题呢?为什么我的调试和发布都是调试和发布?我如何区分它们?

请询问是否需要其他信息。

答案是我认为在Qt project org faq 355

如果你总是接受Qt Creator建议的名称,你可以在你的配置文件中使用以下简单的解决方案,在我的情况下(Qt 5.5)适用于Linux, Mac和Windows:

# to distinguish between debug and release executable as target
# we define the variables releaseExec and debugExec
# this only works if the $$OUT_PWD has "Release" in its name
BDIR = $$OUT_PWD
BDIR_STRIPPED = $$replace(BDIR,Release,)
equals (BDIR,$$BDIR_STRIPPED): CONFIG+= debugExec
else: CONFIG+= releaseExec

我们使用变量releaseExecdebugExec来避免与Qt配置变量的名称冲突。

你现在可以使用switch语句:

releaseExec: warning ("this is a release build")
debugExec: warning ("this is a debug build")