简体   繁体   English

在“使用调试信息发布”模式下构建Qt?

[英]Build Qt in “Release with Debug Info” mode?

Is there a way to build Qt in "Release with Debug info" mode ? 有没有办法在“Release with Debug info”模式下构建Qt? 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 docs has "debug" , "release" but not "release with debug" mode. Qt docs有“debug”,“release”但不是“release with debug”模式。

[Upate] [Upate]

My application works fine with Mingw 32bit Release/Debug and VSC++ Compiler 64bit Debug. 我的应用程序适用于Mingw 32位Release / Debug和VSC ++ Compiler 64bit Debug。

Only crashes on VSC++ 64Bit Release 仅在VSC ++ 64Bit Release上崩溃

Any tips ? 有小费吗 ?

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但我们需要手动将上述条件附加到Qt 4.x default_post.prf

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 . 不支持使用此模式构建Qt,请参阅此错误 You can only do it manually by changing vcproj-files or Makefiles like in the answer of Macke. 你只能通过在Macke的答案中更改vcproj文件或Makefile来手动完成。

在Qt5中,调用configure ,只需添加选项-force-debug-info

Update: See @milanw's answer below. 更新:请参阅下面的@milanw的回答。 This is now supported directly in qmake 现在可以直接在qmake中支持

We use qmake to generate vcproj files to build Qt. 我们使用qmake生成vcproj文件来构建Qt。 I wrote a python script (but sed is fine too) to change the vcproj-files to build with debug information in release too. 我写了一个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))

Building Qt with this mode is not supported, see this bug. 不支持使用此模式构建Qt,请参阅此错误。 You can only do it manually by changing vcproj-files or Makefiles like in the answer of Macke. 你只能通过在Macke的答案中更改vcproj文件或Makefile来手动完成。

May I add that in Qt 4.8, this bug seems to have been fixed. 我可以在Qt 4.8中添加,这个错误似乎已得到修复。 I copied those two lines into my .pro file, and it worked like a charm. 我将这两行复制到我的.pro文件中,它就像一个魅力。

Looks like you need to adjust QMAKE_CFLAGS_RELEASE variable. 看起来您需要调整QMAKE_CFLAGS_RELEASE变量。 In case of gcc you just need to add -g option to add debug info. 对于gcc,您只需添加-g选项即可添加调试信息。

Just select Profile build in the projects tab of Qt Creator rather than the debug or release builds. 只需在Qt Creator的项目选项卡中选择Profile build,而不是调试或发布版本。 It will add a lot of arguments to the qmake call. 它会为qmake调用添加很多参数。

qmake.exe someproject.pro -spec win32-msvc "CONFIG+=qml_debug" 
"CONFIG+=qtquickcompiler" "CONFIG+=force_debug_info" "CONFIG+=separate_debug_info"

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

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