记一次cmake踩坑记录

1. 问题描述

在使用cmake 3.22构建项目,执行cmake命令出现如下错误
CMake Error: CMake was unable to find a build program corresponding to “Ninja”. CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
– Configuring incomplete, errors occurred!

2. 问题分析

通过 cmake --help 发现 ninja 带了*号,表示为默认的构建工具
Generators
The following generators are available on this platform ( marks default):*
Visual Studio 17 2022 = Generates Visual Studio 2022 project files.
Use -A option to specify architecture.
Visual Studio 16 2019 = Generates Visual Studio 2019 project files.
Use -A option to specify architecture.
Visual Studio 15 2017 [arch] = Generates Visual Studio 2017 project files.
Optional [arch] can be “Win64” or “ARM”.

MinGW Makefiles = Generates a make file for use with
mingw32-make.
*Ninja = Generates build.ninja files.

cmake --help 也提示了 参数-G 可以指定构建器名称,
-S = Explicitly specify a source directory.
-B = Explicitly specify a build directory.
-G = Specify a build system generator.
–build   = Build a CMake-generated project binary tree.
–install  = Install a CMake-generated project binary
tree.

3. 解决方法

因为机器上没有装ninja,所以导建构建失败,要么给机器装上ninja要么指定其他的构建器,因为没有使用Ninja的需求,所以使用指定其他构建器的方式

这里选择 MinGW或VS2017 进行构建,因此命令参数改为

#生成构建文件
cmake -G “MinGW Makefiles” -B ./MinGW_build -S ./
cmake -G “Visual Studio 15 2017” -B ./MSVC_build -S ./
#根据已构建的文件进行编译, 这里也可以调用对应编译器进行编译 如make或cl
cmake --build ./MinGW_build
cmake --build ./MSVC_build

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值