Build Qt in “Release with Debug Info” mode?

后端 未结 7 1775
甜味超标
甜味超标 2020-12-30 21:32

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

相关标签:
7条回答
  • 2020-12-30 21:42

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

    0 讨论(0)
  • 2020-12-30 21:42

    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.

    0 讨论(0)
  • 2020-12-30 21:44

    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.

    0 讨论(0)
  • 2020-12-30 21:48

    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

    0 讨论(0)
  • 2020-12-30 21:58

    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.

    0 讨论(0)
  • 2020-12-30 22:00

    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"
    
    0 讨论(0)
提交回复
热议问题