Build Qt in “Release with Debug Info” mode?

廉价感情. 提交于 2019-12-30 02:44:05

问题


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 ?


回答1:


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



回答2:


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




回答3:


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.




回答4:


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




回答5:


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:


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.




回答7:


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"


来源:https://stackoverflow.com/questions/6993061/build-qt-in-release-with-debug-info-mode

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!