Build Qt in “Release with Debug Info” mode?

2019-02-08 03:03发布

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 ?

标签: c++ qt qt4 qmake
7条回答
地球回转人心会变
2楼-- · 2019-02-08 03:36

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

查看更多
beautiful°
3楼-- · 2019-02-08 03:39

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.

查看更多
一夜七次
4楼-- · 2019-02-08 03:42

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))
查看更多
狗以群分
5楼-- · 2019-02-08 03:42

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.

查看更多
混吃等死
6楼-- · 2019-02-08 03:47

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.

查看更多
走好不送
7楼-- · 2019-02-08 03:49

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

查看更多
登录 后发表回答