Consider the following simple C++ program:
// main.cpp
#include <iostream>
int main()
{
std::cout << "Hello World" << std::endl;
return 0;
}
I am using CMake to generate my Makefile for this project, which I then build using GNU Make and g++. My CMakeLists.txt
file looks like this (it is actually more complex, this is of course simplified):
cmake_minimum_required(VERSION 3.20)
project(HelloWorld VERSION 1.0 LANGUAGES CXX)
add_executable(HelloWorld main.cpp)
Everything works, but when building a debug build:
cmake -DCMAKE_BUILD_TYPE=Debug ..
I noticed the debugger flag that is used is -g
. When running make VERBOSE=1
to see what flags are used, here what shows up when compiling main.cpp
:
[ 50%] Building CXX object CMakeFiles/HelloWorld.dir/main.cpp.o
/usr/bin/c++ -g -MD -MT CMakeFiles/HelloWorld.dir/main.cpp.o -MF CMakeFiles/HelloWorld.dir/main.cpp.o.d -o CMakeFiles/HelloWorld.dir/main.cpp.o -c /home/HelloWorld/main.cpp
Notice the -g
flag which is put there automatically by CMake to add debugging information.
How can I change it to -ggdb3
instead?