CMAKE_C_COMPILER not set, after EnableLanguage [duplicate]
Asked Answered
M

1

25

I installed CMake on windows in addition to gcc and g++ compiler I added the variables to the path but still getting the following error could you please help.

enter image description here

-- Building for: NMake Makefiles
CMake Error at CMakeLists.txt:6 (project):
  Running

   'nmake' '-?'

  failed with:

   The system cannot find the file specified


CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred!
See also "C:/Users/DEANHOS/Desktop/peer/cmake tutorial/codeAndTech/sample/CMakeFiles/CMakeOutput.log".

Monmouth answered 29/12, 2021 at 19:34 Comment(3)
You are trying to configure the project for NMake generator, but executable nmake is not accessible on your machine. This is what the first error message about.Ruddie
Thanks @Ruddie you are right. I defined the generator like this cmake -G "MinGW Makefiles" . and the first error disappeared Appreciate itMonmouth
In my case it was because of trying to build (cmake --build ..) before configuring (cmake ..). Any subsequeny configure commands ended up with the above error. Deleting everything in the build directory and rerunning cmake .. fixed it!Swam
A
20

These variables need to be passed on the command line as:

$ cmake -DCMAKE_CXX_COMPILER=/pathto/g++ -DCMAKE_C_COMPILER=/pathto/gcc /pathto/source

or set up before the project() line in CMakeLists.txt:

set( CMAKE_CXX_COMPILER "/pathto/g++" )
set( CMAKE_C_COMPILER "/pathto/gcc" )

project(mytest)
...

or alternatively brought in with the -C <toolchain> command as

# mygcc.cmake 
# toolchain file
set( CMAKE_CXX_COMPILER "/pathto/g++" )
set( CMAKE_C_COMPILER "/pathto/gcc" )
$ cmake -C /pathto/mygcc.cmake /pathto/source
Antifouling answered 29/12, 2021 at 19:38 Comment(2)
is pathto a placeholder? I set my compilers like this is that ok? set( CMAKE_CXX_COMPILER "C:/MinGW/bin/g++" ) set( CMAKE_C_COMPILER "C:/MinGW/bin/gcc" )Helminthology
What do you mean by pathto/source ?Winser

© 2022 - 2024 — McMap. All rights reserved.