CMake 中的调试与发布

Debug vs Release in CMake(CMake 中的调试与发布)
本文介绍了CMake 中的调试与发布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

在 GCC 编译的项目中,

In a GCC compiled project,

  • 如何为每种目标类型(调试/发布)运行 CMake?
  • 如何使用 CMake 指定调试和发布 C/C++ 标志?
  • 我如何表示主可执行文件将使用 g++ 和一个嵌套的库与 gcc 编译?
  • How do I run CMake for each target type (debug/release)?
  • How do I specify debug and release C/C++ flags using CMake?
  • How do I express that the main executable will be compiled with g++ and one nested library with gcc?

推荐答案

使用 CMake,一般建议做一个 源外"构建.在项目的根目录中创建 CMakeLists.txt.然后从您的项目的根目录:

With CMake, it's generally recommended to do an "out of source" build. Create your CMakeLists.txt in the root of your project. Then from the root of your project:

mkdir Release
cd Release
cmake -DCMAKE_BUILD_TYPE=Release ..
make

对于Debug(再次从项目的根目录):

And for Debug (again from the root of your project):

mkdir Debug
cd Debug
cmake -DCMAKE_BUILD_TYPE=Debug ..
make

Release/Debug 将为您的编译器添加适当的标志.还有 RelWithDebInfoMinSizeRel 构建配置.

Release / Debug will add the appropriate flags for your compiler. There are also RelWithDebInfo and MinSizeRel build configurations.

您可以通过指定工具链来修改/添加标志文件,您可以在其中添加CMAKE_<LANG>_FLAGS_<CONFIG>_INIT 变量,例如:

You can modify/add to the flags by specifying a toolchain file in which you can add CMAKE_<LANG>_FLAGS_<CONFIG>_INIT variables, e.g.:

set(CMAKE_CXX_FLAGS_DEBUG_INIT "-Wall")
set(CMAKE_CXX_FLAGS_RELEASE_INIT "-Wall")

有关详细信息,请参阅 CMAKE_BUILD_TYPE.

See CMAKE_BUILD_TYPE for more details.

至于你的第三个问题,我不确定你在问什么.CMake 应自动检测并使用适合您不同源文件的编译器.

As for your third question, I'm not sure what you are asking exactly. CMake should automatically detect and use the compiler appropriate for your different source files.

这篇关于CMake 中的调试与发布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Prevent class inheritance in C++(防止 C++ 中的类继承)
Why should I declare a virtual destructor for an abstract class in C++?(为什么要在 C++ 中为抽象类声明虚拟析构函数?)
Why is Default constructor called in virtual inheritance?(为什么在虚拟继承中调用默认构造函数?)
C++ cast to derived class(C++ 转换为派生类)
C++ virtual function return type(C++虚函数返回类型)
Is there any real risk to deriving from the C++ STL containers?(从 C++ STL 容器派生是否有任何真正的风险?)