35

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 ?

Christophe Weis
  • 2,518
  • 4
  • 28
  • 32
Ashika Umanga Umagiliya
  • 8,988
  • 28
  • 102
  • 185
  • 1
    Sometimes Q_ASSERT statements are the reason for such a behaviour. If you do Q_ASSERT( ( pObject = getObject() ) != NULL ); for example, the line pObject = getObject() won't get executed in release mode. You might check for stuff like that or debug switches. – Tim Meyer Aug 09 '11 at 09:22

8 Answers8

50

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

Top-Master
  • 7,611
  • 5
  • 39
  • 71
milianw
  • 5,164
  • 2
  • 37
  • 41
  • as of now, that is not supported in Qt4 – Sascha Feb 02 '17 at 09:48
  • 1
    CONFIG += force_debug_info – BuvinJ Apr 14 '17 at 20:07
  • Leave out the `release` shown here unless you want to turn your debug sessions in to release! – BuvinJ Apr 14 '17 at 20:09
  • 1
    @BuvinJ: the title of the question is "Release with Debug Info". If you want a real debug build, simply use `CONFIG += debug` - no need to force debug info in a debug build. – milianw Apr 24 '17 at 15:17
  • Perhaps I don't understand the context to which you're referring. Debug / release is handled by selecting one in Creator. Those parameters end up in `CONFIG` automatically. Your release addition here is not a conditional part of the statement, if that's your reasoning. Pasting this line into one's QMake will break that debug/release logic, especially if you also use the recommended means for testing release vs debug in the QMake (evaluating `CONFIG`). This line screwed up a project of mine. I dropped the release part, and all was well. It doesn't harm a debug to duplicate an instruction. – BuvinJ Apr 24 '17 at 15:30
  • ah, now I understand what you are aiming at. I don't use creator and always build via the command line and pass the above in two via the command line. I'll edit the answer – milianw Apr 25 '17 at 13:44
  • Adding `"CONFIG+=force_debug_info"` to my `qmake.exe` call was what I needed to do for making PDBs for qt projects ad-hoc without messing with anyone's project files. – kayleeFrye_onDeck Jun 12 '17 at 20:23
  • Is there any possibility to use it in Visual Studio? And maybe with Qt 4? – Makuna Jun 05 '18 at 06:45
  • Does this approach work for UWP apps destined for Microsoft Store? (My crash logs say symbols not available.) – Paul Masri-Stone Oct 22 '19 at 12:04
  • What would be the equivalent for `CONFIG += force_debug_info` in a CMakeLists.txt file? – Splines Oct 09 '22 at 22:30
  • 1
    @Splines via the standard `CMAKE_BUILD_TYPE=RelWithDebInfo` – milianw Oct 11 '22 at 07:27
16

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.

Top-Master
  • 7,611
  • 5
  • 39
  • 71
hmuelner
  • 8,093
  • 1
  • 28
  • 39
14

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

Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324
6

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))
Macke
  • 24,812
  • 7
  • 82
  • 118
1

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.

Yellow
  • 3,955
  • 6
  • 45
  • 74
1

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.

Bowdzone
  • 3,827
  • 11
  • 39
  • 52
ks1322
  • 33,961
  • 14
  • 109
  • 164
0

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"
night
  • 75
  • 8
0

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