C++ 在“带有调试信息的发布”模式下构建 Qt?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6993061/
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
Build Qt in "Release with Debug Info" mode?
提问by Ashika Umanga Umagiliya
Is there a way to build Qt in "Release with Debug info" mode ? My application crashes only in "release" mode (works fine in Debug mode) and seems the issue comes from Qt (may be a bug in Qt).So I want to see the debug info of Qt.
有没有办法在“带调试信息的发布”模式下构建 Qt?我的应用程序仅在“发布”模式下崩溃(在调试模式下工作正常),似乎问题来自 Qt(可能是 Qt 中的错误)。所以我想查看 Qt 的调试信息。
Qt docshas "debug" , "release" but not "release with debug" mode.
Qt 文档有 "debug" 、 "release" 但没有 "release with debug" 模式。
[Upate]
[更新]
My application works fine with Mingw 32bit Release/Debug and VSC++ Compiler 64bit Debug.
我的应用程序在 Mingw 32bit Release/Debug 和 VSC++ Compiler 64bit Debug 下运行良好。
Only crashes on VSC++ 64Bit Release
仅在 VSC++ 64Bit Release 上崩溃
Any tips ?
有小费吗 ?
采纳答案by Macke
Update: See @milanw's answer below. This is now supported directly in qmake
更新:见下面@milanw 的回答。这现在在 qmake 中直接支持
We use qmake to generate vcproj files to build Qt. I wrote a python script (but sed is fine too) to change the vcproj-files to build with debug information in release too.
我们使用 qmake 生成 vcproj 文件来构建 Qt。我写了一个 python 脚本(但 sed 也很好)来更改 vcproj 文件,以便在发布时使用调试信息进行构建。
Having debug info is indeed invaluable for stack traces that go back and forth between Qt and our app.
拥有调试信息对于在 Qt 和我们的应用程序之间来回移动的堆栈跟踪确实是无价的。
Here's the relevant snippet:
这是相关的片段:
for root, dirs, files in os.walk( qt_build_dir ):
for f in files:
if not f.endswith('.vcproj'):
continue
output = []
with open(pj(root, f), 'r') as file:
for line in file.readlines():
line = line.strip()
if 'DebugInformationFormat="0"' == line:
output.append('\t\t\t\tDebugInformationFormat="3"')
elif 'GenerateDebugInformation="false"' == line:
output.append('\t\t\t\tGenerateDebugInformation="true"')
else:
output.append(line)
with open(pj(root, f), 'w') as file:
file.write('\n'.join(output))
回答by milianw
Old question, I know. But nowadays, you can simply use
老问题,我知道。但是现在,你可以简单地使用
CONFIG += force_debug_info
to get debug symbols even in release mode. When you use QMake
via the command line, I usually do this to get a release build with debug info:
即使在发布模式下也能获得调试符号。当您QMake
通过命令行使用时,我通常这样做是为了获得带有调试信息的发布版本:
qmake CONFIG+=release CONFIG+=force_debug_info path/to/sources
this will enable below conditions of Qt5/mkspecs/features/
default_post.prf:
这将启用Qt5/mkspecs/features/
default_post.prf 的以下条件:
force_debug_info|debug: CONFIG += debug_info
force_debug_info {
QMAKE_CFLAGS_RELEASE = $$QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO
QMAKE_CXXFLAGS_RELEASE = $$QMAKE_CXXFLAGS_RELEASE_WITH_DEBUGINFO
QMAKE_LFLAGS_RELEASE = $$QMAKE_LFLAGS_RELEASE_WITH_DEBUGINFO
}
which would even work for Qt 4.x
but we would need to manually append above conditions into default_post.prf
for Qt 4.x
这甚至可以工作,Qt 4.x
但我们需要手动将上述条件附加到default_post.prf
forQt 4.x
回答by hmuelner
I use this in my qmake files to build my release versions with debuginfo:
我在我的 qmake 文件中使用它来使用 debuginfo 构建我的发布版本:
QMAKE_CXXFLAGS_RELEASE = $$QMAKE_CXXFLAGS_RELEASE_WITH_DEBUGINFO
QMAKE_CFLAGS_RELEASE = $$QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO
QMAKE_LFLAGS_RELEASE = $$QMAKE_LFLAGS_RELEASE_WITH_DEBUGINFO
This way you can at least check if the crash happens in your code. Building Qt with this mode is not supported, see this bug. You can only do it manually by changing vcproj-files or Makefiles like in the answer of Macke.
这样你至少可以检查崩溃是否发生在你的代码中。不支持使用此模式构建 Qt,请参阅此错误。您只能通过更改 vcproj-files 或 Makefiles 手动完成,就像 Macke 的回答一样。
回答by Mariusz Wawrzonkowski
In Qt5, when calling configure
, just simply add option -force-debug-info
在 Qt5 中,调用时configure
,只需添加选项-force-debug-info
回答by ks1322
Looks like you need to adjust QMAKE_CFLAGS_RELEASE
variable. In case of gcc you just need to add -goption to add debug info.
看起来你需要调整QMAKE_CFLAGS_RELEASE
变量。在 gcc 的情况下,您只需要添加-g选项即可添加调试信息。
回答by Yellow
Building Qt with this mode is not supported, see this bug. You can only do it manually by changing vcproj-files or Makefiles like in the answer of Macke.
不支持使用此模式构建 Qt,请参阅此错误。您只能通过更改 vcproj-files 或 Makefiles 来手动完成,就像 Macke 的回答一样。
May I add that in Qt 4.8, this bug seems to have been fixed. I copied those two lines into my .pro file, and it worked like a charm.
我可以补充一点,在 Qt 4.8 中,这个错误似乎已被修复。我将这两行复制到我的 .pro 文件中,它就像一个魅力。
回答by night
Just select Profile build in the projects tab of Qt Creator rather than the debug or release builds. It will add a lot of arguments to the qmake call.
只需在 Qt Creator 的项目选项卡中选择 Profile build 而不是 debug 或 release build。它将为 qmake 调用添加很多参数。
qmake.exe someproject.pro -spec win32-msvc "CONFIG+=qml_debug"
"CONFIG+=qtquickcompiler" "CONFIG+=force_debug_info" "CONFIG+=separate_debug_info"