Creating symbol table for gdb using cmake
CmakeDebug SymbolsCmake Problem Overview
Is there any way to create only symbol table using cmake for gdb ?
Cmake Solutions
Solution 1 - Cmake
Add this line to the file CMakeLists.txt:
set(CMAKE_BUILD_TYPE Debug)
Solution 2 - Cmake
compile in Release mode optimized but adding debug symbols, useful for profiling :
cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo ...
or compile with NO optimization and adding debug symbols :
cmake -DCMAKE_BUILD_TYPE=Debug ...
Solution 3 - Cmake
If you need the debug symbols for profiling then paste this into CMakeLists.txt
:
set(CMAKE_BUILD_TYPE RelWithDebInfo)
Solution 4 - Cmake
If you're using QtCreator, remove (or comment out) any line containing CMAKE_BUILD_TYPE
:
# set(CMAKE_BUILD_TYPE Debug)
# set(CMAKE_BUILD_TYPE Release) <- comment out such lines
Reason: if you explicitly set CMAKE_BUILD_TYPE in your CmakeLists.txt, QtCreator will not allow you to set any other target.
Solution 5 - Cmake
The usual way to produce debugging information for gdb
is to pass -g
to the gcc
or g++
compiler (and also at linking time).
Look into the Cmake FAQ for how to get a debuggable executable.