首页 > 解决方案 > 没有这样的文件或目录编译简约 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()
{
}

标签: c++cmake

解决方案


您需要从中删除g++ CMAKE_CXX_FLAGS 因为您将在其中传递编译器标志。

SET(CMAKE_CXX_FLAGS  "-std=c++17 -pedantic -Wall -Wextra -Werror -Weffc++")

推荐阅读