C++ 如何使用 cmake 设置 GDB 调试标志?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10005982/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 13:30:15  来源:igfitidea点击:

How do you set GDB debug flag with cmake?

c++cmake

提问by Fantastic Mr Fox

I have tried setting the debug flags using the

我曾尝试使用设置调试标志

set

command in cmakebut I cam unsure what to add. I have been told things like DEBUG=truebut so far i am unable to find the correct flag to set.

命令,cmake但我不确定要添加什么。有人告诉我这样的事情,DEBUG=true但到目前为止我无法找到要设置的正确标志。

回答by Fredrik Jansson

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

如果要在编译时为调试构建(包括源信息,即-g),请使用

cmake -DCMAKE_BUILD_TYPE=Debug <path>

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

如果要构建发布版本,可以使用

cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo <path>

回答by Fantastic Mr Fox

Alternatively you can use the CMAKE GUI to make this change. Doing ccmakewith the project will yield a screen similar to this:

或者,您可以使用 CMAKE GUI 进行此更改。做ccmake该项目将产生类似这样的画面:

enter image description here

在此处输入图片说明

Entering Debugin the CMAKE_BUILD_TYPEfield will allow you to build with debug flags.

在该字段中输入DebugCMAKE_BUILD_TYPE将允许您使用调试标志进行构建。