I have tried setting the debug flags using the
set
command in cmake but I cam unsure what to add. I have been told things like DEBUG=true but so far i am unable to find the correct flag to set.
c++cmake
Share
Follow
edited Apr 3, 2015 at 15:20
asked Apr 4, 2012 at 6:30
Fantastic Mr Fox's user avatar
Fantastic Mr Fox
32.6k2727 gold badges9696 silver badges175175 bronze badges
Add a comment
2 Answers
Sorted by:
Highest score (default)
78
If you want to build for debug (including source information, i.e. -g) when compiling, use
cmake -DCMAKE_BUILD_TYPE=Debug
If you want to build a release build, you can use
cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo
Share
Follow
answered Apr 4, 2012 at 6:37
Fredrik Jansson's user avatar
Fredrik Jansson
3,77433 gold badges3030 silver badges3333 bronze badges
16
This isn't working for me. When I try to run gdb, my backtraces consist entirely of memory addresses and question marks with no function names or anything. –
Translunar
Jun 5, 2014 at 21:04
2
set the path in the gdb if its not set to the source file directory by using below gdb> directory "directory path" –
ravi.zombie
Aug 13, 2014 at 2:02
1
you can use set(CMAKE_CXX_FLAGS "-g") in CMakeLists.txt –
Chintan Patel
May 15, 2018 at 5:57
Add a comment
2
Alternatively you can use the CMAKE GUI to make this change. Doing ccmake with the project will yield a screen similar to this:
enter image description here
Entering Debug in the CMAKE_BUILD_TYPE field will allow you to build with debug flags.
Share
Follow
edited Jun 20, 2020 at 9:12
Community's user avatar
CommunityBot
111 silver badge
answered Dec 27, 2018 at 7:18
Fantastic Mr Fox's user avatar
Fantastic Mr Fox
32.6k2727 gold badges9696 silver badges175175 bronze badges
For a person new to using CMake, ccmake is an excellent solution. I'd suggest that RelWithDebInfo might be more helpful than Debug for the CMAKE_BUILD_TYPE. It would also be good to mention that they should hit g to generate after editing. If you wanted to go the extra mile, you could include all the keystrokes (/ to start searching type to find BUILD_TYPE, Enter to start editing the field...) –
hackerb9
Sep 13, 2021 at 2:01