In a Windows QT application, I've successfully managed to call SetUnhandledExceptionFilter()
and write out a minidump once the program crashes unexpectedly. However, as I've learnt here, we need to instruct the compiler to create a "Program-Debug Data Base" (pdb file) with vital information for post-mortem code debugging, e.g. method and symbol names etc. Otherwise, the dump is kind of worthless when opened in WinDbg, as we don't get any meaningful stack traces and I need to see at which line my program crashed exactly. So my goal here is to generate.pdb files alongside the release build (to store them in a private archive for possible debugging scenarios when trying to debug a crash on the customer side).
I'm using a CMakeLists.txt
file in QT Creator and don't get any .pdb files upon building. Based on this forum post answer and this answer, I came up with this:
if (${CMAKE_BUILD_TYPE} STREQUAL "MinSizeRel")
message("Configure with PDB debug information")
set(QMAKE_CLFAGS_RELEASE "${QMAKE_CFLAGS_RELEASE} /Zi")
set(QMAKE_LFLAGS_RELEASE "${QMAKE_LFLAGS_RELEASE} /DEBUG /OPT:REF /OPT:ICF")
endif()
Unfortunately, this does not work, i.e. in my out
folder under the respective release build folder, I do not find any .pdb files. The if(...)
clause should not be the problem, as I see the message "Configure with PDB debug information" in the "General Messages" section of QT Creator when the project is built.
I've also tried to add
set(CMAKE_PDB_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/pdb")
set(CMAKE_COMPILE_PDB_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/pdb")
with no luck. I also had no luck with:
add_compile_options("/Zi")
add_link_options("/DEBUG")
add_link_options("/OPT:REF /OPT:ICF")
The values QMAKE_CLFAGS_RELEASE
and QMAKE_LFLAGS_RELEASE
are correctly populated, so I don't know what I'm missing to get the .pdb files.
Edit: Here is my current CMakeLists.txt
file in Qt Creator.
cmake_minimum_required(VERSION 3.5)
project(ProjectName VERSION 0.1 LANGUAGES CXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
if (${CMAKE_BUILD_TYPE} STREQUAL "MinSizeRel")
message("Configure with PDB debug information")
set(CMAKE_PDB_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/pdb")
set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} /Zi /DEBUG")
set(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} /Zi /DEBUG")
endif()
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets)
find_package(Qt6 REQUIRED COMPONENTS Network)
set(PROJECT_SOURCES
... (cpp and header files list of my project)
)
# https://doc.qt.io/qt-6/qmessagelogcontext.html
# By default, QMessageLogContext only captures in Debug mode,
# we change this so that this information is still available in other modes, e.g. Release mode
add_definitions("-DQT_MESSAGELOGCONTEXT")
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
qt_add_executable(ProjectName
MANUAL_FINALIZATION
${PROJECT_SOURCES}
)
else()
add_executable(ProjectName
${PROJECT_SOURCES}
)
endif()
target_link_libraries(ProjectName
PRIVATE Qt${QT_VERSION_MAJOR}::Widgets
PRIVATE Qt6::Network
)
set_target_properties(ProjectName PROPERTIES
WIN32_EXECUTABLE TRUE
)
install(TARGETS ProjectName
BUNDLE DESTINATION .
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
if(QT_VERSION_MAJOR EQUAL 6)
qt_finalize_executable(ProjectName)
endif()
While building the project, I get this error (multiples times):
g++.exe: warning: /Zi: linker input file unused because linking not done
g++.exe: error: /Zi: linker input file not found: No such file or directory
g++.exe: warning: /DEBUG: linker input file unused because linking not done
g++.exe: error: /DEBUG: linker input file not found: No such file or directory
ninja: build stopped: subcommand failed.
14:11:19: The process "C:\Qt\Tools\CMake_64\bin\cmake.exe" exited with code 1.
Error while building/deploying project ProjectName (kit: Desktop Qt 6.3.1 MinGW 64-bit)
When executing step "Build"
The issue pane in Qt contains these messages multiple times:
/Zi: linker input file unused because linking not done
error: /Zi: linker input file not found: No such file or directory
/DEBUG: linker input file unused because linking not done
The build commands passed to g++ by Qt are as follows:
C:\Qt\Tools\mingw1120_64\bin\g++.exe -DMINGW_HAS_SECURE_API=1 -DQT_CORE_LIB -DQT_GUI_LIB -DQT_MESSAGELOGCONTEXT -DQT_NEEDS_QMAIN -DQT_NETWORK_LIB -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DUNICODE -DWIN32 -DWIN64 -D_ENABLE_EXTENDED_ALIGNED_STORAGE -D_UNICODE -D_WIN64 -IE:/project/path/out/minsizerelease -IE:/project/path/src -IE:/project/path/out/minsizerelease/ProjectName_autogen/include -isystem C:/Qt/6.3.1/mingw_64/include/QtCore -isystem C:/Qt/6.3.1/mingw_64/include -isystem C:/Qt/6.3.1/mingw_64/mkspecs/win32-g++ -isystem C:/Qt/6.3.1/mingw_64/include/QtWidgets -isystem C:/Qt/6.3.1/mingw_64/include/QtGui -isystem C:/Qt/6.3.1/mingw_64/include/QtNetwork -Os -DNDEBUG /Zi /DEBUG -std=gnu++17 -MD -MT CMakeFiles/ProjectName.dir/qtutil/qslotthrower.cpp.obj -MF CMakeFiles\ProjectName.dir\qtutil\qslotthrower.cpp.obj.d -o CMakeFiles/ProjectName.dir/qtutil/qslotthrower.cpp.obj -c E:/project/path/src/qtutil/qslotthrower.cpp