Debug vs Release in 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 withgcc?
推荐答案
使用 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 将为您的编译器添加适当的标志.还有 RelWithDebInfo 和 MinSizeRel 构建配置.
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 中的调试与发布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:CMake 中的调试与发布
基础教程推荐
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 我有静态或动态 boost 库吗? 2021-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 这个宏可以转换成函数吗? 2022-01-01
- 常量变量在标题中不起作用 2021-01-01
