在 GCC 编译的项目中,
In a GCC compiled project,
g++
和一个嵌套的库与 gcc
编译?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
将为您的编译器添加适当的标志.还有 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 中的调试与发布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!