CMake on Windows

I try to run cmake on windows and I get the following error:

-- The C compiler identification is unknown CMake Error at CMakeLists.txt:3 (PROJECT): The CMAKE_C_COMPILER: cl is not a full path and was not found in the PATH. To use the NMake generator with Visual C++, cmake must be run from a shell that can use the compiler cl from the command line. This environment is unable to invoke the cl compiler. To fix this problem, run cmake from the Visual Studio Command Prompt (vcvarsall.bat). Tell CMake where to find the compiler by setting either the environment variable "CC" or the CMake cache entry CMAKE_C_COMPILER to the full path to the compiler, or to the compiler name if it is in the PATH. 

However, my environment variable "CC" is set!

 >>echo %CC% C:\Anaconda2\MinGW\x86_64-w64-mingw32\bin\gcc.exe 
+7
c ++ c cmake
source share
1 answer

Turning my comments back

Since the CMake error message is misleading, I think this requires a more detailed answer.

In short, you are facing a chicken-and-egg problem.

The discovery of the CMake compiler is great, but since - during the first attempt -

  • you did not provide an explicit generator for use with -G
  • he could not find the installed Visual Studio.
  • he could not find the C / C ++ compiler in the PATH environment
  • he could not find the CC environment variable defined with the full path to the compiler

it was nmake by default.

Now the problem is: it remembers your implicit generator / compiler selection in the variable cache (see CMAKE_GENERATOR in CMakeCache.txt ). Which is a very useful feature if you have several compilers installed.

But if you then declare the CC environment variable - as the error message indicates - it is too late, since your generator selection was saved the first time.

I see two possible options:

  • Deselect the generator by setting the correct number with cmake.exe -G "MinGW Makefiles" .. (as indicated by the answer pointed to by @Guillaume)
  • Delete the project's binary output directory (including CMakeCache.txt ) and make cmake.exe .. after adding your bin compiler bin to the PATH environment.

References

  • Running CMake on Windows
  • What is the default CMake generator on Windows?
  • CMake error in CMakeLists.txt: 30 (project): No CMAKE_C_COMPILER can be found
  • CMake: how to specify the version of Visual C ++ to work with?
+6
source share

All Articles