Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
[SOLVED] How to build Release with debug info (MinGW)
I need to debug a release build of my application and therefore need to add debug info to the release build. I added the following lines to my pro file:
QMAKE_CXXFLAGS_RELEASE *= -g
QMAKE_CFLAGS_RELEASE *= -g
If I attach QtCreator to the running application, the source files view does not list any source file of my application but lists some source files of some libraries (dlls) that I have built without qmake and that I have linked to my application. I can not start debug session for the release build in eclipse and the size of the generated EXE and DLL files is much smaller than the ones generated during debug built. So I assume that there are no debug symbols in the EXE and DLL files although I have added the -g option to my release build. Debugging the debug version of my application is no problem - so this is no issue of missing source files or invalid paths.
If I compile the release build I can see the following compiler output for each source file:
g++ -c -O2 -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -I"C:....
So the flag -g is properly passed to the compiler. If I remove the -g flag (remove QMAKE_CXXFLAGS_RELEASE *= -g
QMAKE_CFLAGS_RELEASE *= -g) the size of the application file and DLLs does not change. So obviously the -g option does not add any debug information to the release build.
So why does my release build does not contain debug symbols and how should I change my pro file to generate a release build with debug info?
sabrog last edited by
May be problem in "strip" tool, try unset this flags:
Thank you for your answer. Too bad that this does not solve the issue.
Ok, I solved it myself.
The file qt\mkspecs\default\qmake.conf defines the following linker flags:
QMAKE_LFLAGS_RELEASE = -Wl,-s
The linker flag -s means: Omit all symbol information from the output file.
So it is the linker that removes all debug information from release build. So if you want to build a release version with debug info you need to define the following in your pro file:
QMAKE_CXXFLAGS_RELEASE += -g
QMAKE_CFLAGS_RELEASE += -g
Now I can properly debug the release build of my application.