How do you set GDB debug flag with cmake?

Go To


I have tried setting the debug flags using the


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.

2012-04-04 06:30
by Fantastic Mr Fox


If you want to build for debug (including source information, i.e. -g) when compiling, use

cmake -DCMAKE_BUILD_TYPE=Debug <path>

If you want to build a release build, you can use

cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo <path>
2012-04-04 06:37
by Fredrik Jansson
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 - Doctor Mohawk 2014-06-05 21:04
set the path in the gdb if its not set to the source file directory by using below gdb> directory "directory path - ravi.zombie 2014-08-13 02:02
you can use set(CMAKECXXFLAGS "-g") in CMakeLists.tx - Chintan Patel 2018-05-15 05:57


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.

2018-12-27 07:18
by Fantastic Mr Fox