0

I tried making a minimalistic try to learn how to use cmake with c++. When I tried it my first time, it worked. Then I did it in a second folder and I got compile errors when running make. All I did was run cmake . and then make. What does the error mean?

error

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++")

main.cc:

int main()
{
}
dekuShrub
  • 466
  • 4
  • 20
  • 4
    If you `make VERBOSE=1` you're likely to see what what (bad) effect `CMAKE_CXX_FLAGS` containing `g++` is having on your entire `g++` command-line. – timemage Jul 01 '21 at 14:24
  • 2
    Remove `g++` from the flag string. – Igor R. Jul 01 '21 at 14:26
  • 1
    You're right, it makes sense now. I didn't understand that "g++" was the file it was referring to. – dekuShrub Jul 01 '21 at 14:28
  • 1
    `-std=c++17` there is a CMake way to do this. Related: [https://stackoverflow.com/a/52382437/487892](https://stackoverflow.com/a/52382437/487892) – drescherjm Jul 01 '21 at 14:51

1 Answers1

0

You need to remove g++ from CMAKE_CXX_FLAGS as you shall pass compiler flags in it.

SET(CMAKE_CXX_FLAGS  "-std=c++17 -pedantic -Wall -Wextra -Werror -Weffc++")
Altaf
  • 2,838
  • 1
  • 16
  • 8