Several ways to add the -g compilation option to cmake

Sometimes we need to use gdb to debug a program and add the "-g" compilation option to the program. So how to add the "-g" compilation option to the project built by cmake? Two ways are collected here;

The first

Modify CMakelist.txt and add the line "add_definitions("-Wall -g")";

The second kind

 When executing cmake, add the -DCMAKE_BUILD_TYPE=Debug compilation option.

cmake -DCMAKE_BUILD_TYPE=Debug ......

It is recommended to use the second method without changing CMakelist.txt.

How to print detailed information on the makefile generated by cmake compilation? Add "VERBOSE=1" when executing make. If you want to speed up compilation, you can add the -j 10 option. The maximum value of the following number is the number of processor cores of the machine.

Guess you like

Origin blog.csdn.net/heibao111728/article/details/131092329