The*_*ist 6 c++ debugging qt qmake qt5
所以我使用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
Run Code Online (Sandbox Code Playgroud)
我想以这种方式自动化,从Qt Creator中选择调试或发布就足以创建正确的版本.我看到其他的解决方案,如一个在这里,但是,这并不工作.调试和发布时调用以下命令时,可以看到它不起作用的原因:
message($$CONFIG)
Run Code Online (Sandbox Code Playgroud)
这将打印qmake的配置.结果如下:
发布:
lex yacc调试异常depend_includepath testcase_targets import_plugins import_qpa_plugin rtti_off incremental_off windows qt warn_on release link_prl incremental 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 incremental 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
请注意,两者都包含调试和释放......我想知道为什么......
我想指出我从源代码编译了这个Qt版本.但是当我这样做时,并没有奇怪的东西.我使用以下命令编译它(配置然后用简单的nmake编译):
configure -debug-and-release -opensource -platform win32-msvc2013 -opengl desktop -static -nomake examples -nomake tests
Run Code Online (Sandbox Code Playgroud)
我通过添加命令来尝试一个枯燥的解决方案:debug:CONFIG-=release在我的make文件中,但是当我选择从Qt Creator发布时,这将导致发行版本变为30 MB大小而不是14 MB的调试.
我的qmake文件是一个典型的文件.以下是可能与问题有关的部分.其他部分只是添加文件和库和路径:
QMAKE_CFLAGS += /MT
QT += core gui
unix:QMAKE_CXXFLAGS += -std=c++11
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = MyProg
TEMPLATE = app
Run Code Online (Sandbox Code Playgroud)
那么为什么会出现这个问题呢?为什么我的调试或发布是调试和发布?我该如何区分它们?
请询问您是否需要任何其他信息.
答案是我认为在Qt 项目组织 faq 355中
如果您始终接受 Qt Creator 为您的构建建议的名称,您可以在您的 pro 文件中使用以下简单的解决方案,在我的例子中(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
Run Code Online (Sandbox Code Playgroud)
我们使用变量releaseExec和debugExec来避免与 Qt CONFIG 变量发生名称冲突。
您现在可以使用 switch 语句:
releaseExec: warning ("this is a release build")
debugExec: warning ("this is a debug build")
Run Code Online (Sandbox Code Playgroud)