Because CMake’s error message is misleading here, I think it warrants a little more detailed answer.
In short, you ran into a chicken-and-egg kind of a problem.
CMake’s compiler detection is mighty, but since – during the first try –
- you didn’t give any explicit generator to use with
-G
- it couldn’t find a Visual Studio installed
- it couldn’t find any C/C++ compiler in your
PATH
environment - it couldn’t find a
CC
environment variable defined with the full path to a compiler
It was defaulting to nmake
.
Now here comes the problem: it does remember your implicit generator/compiler choice in it’s variable cache (see CMAKE_GENERATOR
in CMakeCache.txt
). What is a very useful feature, if you have multiple compilers installed.
But if you then declare the CC
environment variable – as the error message suggests – it’s too late since your generator’s choice was remembered in the first try.
I see two possible ways out of this:
- Overrule the generator choice by given the right one with
cmake.exe -G "MinGW Makefiles" ..
(as the answer linked by @Guillaume suggests) - Delete your project’s binary output directory (including
CMakeCache.txt
) and docmake.exe ..
after you added your compiler’sbin
folder to yourPATH
environment.
References
- Running CMake on Windows
- What is the default generator for CMake in Windows?
- CMake error at CMakeLists.txt:30 (project): No CMAKE_C_COMPILER could be found
- CMake: how to specify the version of Visual C++ to work with?