Creating symbol table for gdb using cmake

CmakeDebug Symbols

Cmake 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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionVivek GoelView Question on Stackoverflow
Solution 1 - CmakeJespaView Answer on Stackoverflow
Solution 2 - CmakeguillopteroView Answer on Stackoverflow
Solution 3 - CmakeHadusView Answer on Stackoverflow
Solution 4 - CmakeMichał LeonView Answer on Stackoverflow
Solution 5 - CmakeBasile StarynkevitchView Answer on Stackoverflow