c++ - 没有这样的文件或目录编译简约 cmake 示例
问题描述
我尝试做一个极简主义的尝试来学习如何将 cmake 与 c++ 一起使用。当我第一次尝试时,它起作用了。然后我在第二个文件夹中做了它,运行 make 时出现编译错误。我所做的只是运行cmake .
,然后make
。错误是什么意思?
错误
Scanning dependencies of target hello
[ 50%] Building CXX object CMakeFiles/hello.dir/main.cc.o
c++: error: g++: No such file or directory
CMakeFiles/hello.dir/build.make:62: recipe for target 'CMakeFiles/hello.dir/main.cc.o' failed
make[2]: *** [CMakeFiles/hello.dir/main.cc.o] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/hello.dir/all' failed
make[1]: *** [CMakeFiles/hello.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
CMakeLists.txt
cmake_minimum_required(VERSION 3.10.2) # set version to same as on system
project(hello) # set project name to something
add_executable(hello main.cc) # the executable should be called "hello"
SET(CMAKE_CXX_FLAGS "g++ -std=c++17 -pedantic -Wall -Wextra -Werror -Weffc++")
主.cc:
int main()
{
}
解决方案
您需要从中删除g++
,CMAKE_CXX_FLAGS
因为您将在其中传递编译器标志。
SET(CMAKE_CXX_FLAGS "-std=c++17 -pedantic -Wall -Wextra -Werror -Weffc++")
推荐阅读
- c++ - 如何将十六进制字符串转换为字符数组
- azure - 使用 Azure 数据工厂删除 Excel 文件中的特定行
- python - 某些 logger.level 不适用于我的自定义 Json 记录器
- macos - 带有 VirtualBox 的 Minikube 开始无法在 MacOS Monterey 上运行
- r - 查看器和保存的绘图之间的ggplot线型图例不同
- discord - Discord.js 不断更改昵称和头像
- oracle - 使用编译错误创建的触发器。PL/SQL
- r - 将逗号分隔的向量转换为由 + 分隔的预测变量列表
- html - 在输入字段中输入时如何更改电子邮件输入颜色
- excel - Excel我们需要字符串数据跳过空白和排序