在“Release with Debug Info”中构建 Qt模式?

发布于 2024-11-28 14:47:27 字数 339 浏览 0 评论 0原文

有没有办法在“带有调试信息的发布”模式下构建Qt?我的应用程序仅在“发布”模式下崩溃(在调试模式下工作正常),似乎问题来自 Qt(可能是 Qt 中的错误)。所以我想查看 Qt 的调试信息。

Qt 文档 有“调试”、“发布”,但没有“以调试方式发布”。

[更新]

我的应用程序在 Mingw 32 位发布/调试和 VSC++ 编译器 64 位调试中运行良好。

仅在 VSC++ 64 位版本上崩溃

有任何提示吗?

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 docs has "debug" , "release" but not "release with debug" mode.

[Upate]

My application works fine with Mingw 32bit Release/Debug and VSC++ Compiler 64bit Debug.

Only crashes on VSC++ 64Bit Release

Any tips ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

三生一梦 2024-12-05 14:47:28

老问题,我知道。但如今,

CONFIG += force_debug_info

即使在发布模式下,您也可以简单地使用来获取调试符号。当您通过命令行使用 QMake 时,我通常这样做是为了获得带有调试信息的发布版本:

qmake CONFIG+=release CONFIG+=force_debug_info path/to/sources

这将启用以下条件的 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
}

甚至适用于 Qt 4.x 但我们需要手动追加将上述条件放入 Qt 4.xdefault_post.prf

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 CONFIG+=release CONFIG+=force_debug_info path/to/sources

this will enable below conditions of 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

坐在坟头思考人生 2024-12-05 14:47:28

我在 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

这样您至少可以检查代码中是否发生崩溃。
不支持使用此模式构建 Qt,请参阅此 bug
您只能通过更改 vcproj 文件或 Makefile 来手动完成此操作,如 Macke 的答案中所示。

I use this in my qmake files to build my release versions with 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.

哥,最终变帅啦 2024-12-05 14:47:28

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

In Qt5, when calling configure, just simply add option -force-debug-info

且行且努力 2024-12-05 14:47:28

更新:请参阅下面@milanw 的回答。现在 qmake 直接支持这一点

我们使用 qmake 生成 vcproj 文件来构建 Qt。我编写了一个 python 脚本(但 sed 也很好)来更改 vcproj 文件以在发行版中使用调试信息进行构建。

对于 Qt 和我们的应用程序之间来回的堆栈跟踪来说,拥有调试信息确实非常宝贵。

这是相关的片段:

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))

Update: See @milanw's answer below. This is now supported directly in 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.

Having debug info is indeed invaluable for stack traces that go back and forth between Qt and our app.

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))
—━☆沉默づ 2024-12-05 14:47:28

不支持使用此模式构建 Qt,请参阅此错误。您只能通过更改 vcproj 文件或 Makefile 来手动完成此操作,如 Macke 的答案中所示。

我想补充一下,在 Qt 4.8 中,这个 bug 似乎已经被修复了。我将这两行复制到我的 .pro 文件中,它的效果非常好。

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.

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.

沫离伤花 2024-12-05 14:47:28

看起来您需要调整 QMAKE_CFLAGS_RELEASE< /code>变量。如果是 gcc,您只需添加 -g 选项即可添加调试信息。

Looks like you need to adjust QMAKE_CFLAGS_RELEASE variable. In case of gcc you just need to add -g option to add debug info.

破晓 2024-12-05 14:47:28

对于linux用户

./configure -prefix /opt/qt -release -force-debug-info -opensource -nomaketests -no-avx -no-avx2 -no-avx512

make V=1 -j8
make install

ps:cat /proc/cpuinfo, 如果你有 avx avx2 avx512 然后删除 -no-avx -no-avx2 -no-avx512

for linux user

./configure -prefix /opt/qt -release -force-debug-info -opensource -nomake tests -no-avx -no-avx2 -no-avx512

make V=1 -j8
make install

ps:cat /proc/cpuinfo, if you have avx avx2 avx512 then remove -no-avx -no-avx2 -no-avx512

故事和酒 2024-12-05 14:47:28

只需在 Qt Creator 的项目选项卡中选择配置文件构建,而不是调试或发布构建。它会向 qmake 调用添加很多参数。

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

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.

qmake.exe someproject.pro -spec win32-msvc "CONFIG+=qml_debug" 
"CONFIG+=qtquickcompiler" "CONFIG+=force_debug_info" "CONFIG+=separate_debug_info"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文