Issue
I am trying to build a c++ project using cmake. I am using sublime text on windows. Here is my CMakeLists.txt configuration:
project(Arena)
cmake_minimum_required(VERSION 3.0)
set(CMAKE_C_COMPILER C:\MinGW\bin)
set(CMAKE_CXX_COMPILER C:\MinGW\bin)
When I run the cmake .
command, I get the following error messages:
-- Building for: NMake Makefiles
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
CMake Error at CMakeLists.txt:1 (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.
CMake Error at CMakeLists.txt:1 (project):
The CMAKE_CXX_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 "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
to the compiler, or to the compiler name if it is in the PATH.
The error message says that the cl
compiler is not found, this is because I have not installed it. But I have installed the MINGW GNU compiler collection (GCC). These are in my PATH
at C:\MinGW\bin
. How do I configure cmake to compile using the compilers I already have on my machine?
Stupid Question Alert: I am also confused as to why the error message is talking about an NMake generator with Visual C++
because I am not using Visual Studio?
Attempt 1:
Ran the cmake command like so cmake . -G "MinGW Makefiles"
, got the following error:
CMake Error: CMake was unable to find a build program corresponding to "MinGW Makefiles". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
CMake Error: CMake was unable to find a build program corresponding to "MinGW Makefiles". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
Solution
I am also confused as to why the error message is talking about an NMake generator with Visual C++ because I am not using Visual Studio?
It seems that your CMake decided that "NMake Makefiles" was the default generator type, which means the CMake configuration step was outputting project/makefiles for NMake.
How do I configure cmake to compile using the compilers I already have on my machine?
When you run CMake, specify the generator:
cmake . -G "MinGW Makefiles"
There are also some things you should do to improve/fix your CMakeLists.txt:
Specify the minimum version before the project line.
Add the following lines to tell CMake where your MinGW binaries are:
set(CMAKE_MAKE_PROGRAM <your make program path>)
set(CMAKE_C_COMPILER <your c compiler path>)
set(CMAKE_CXX_COMPILER <your c++ compiler path>)
This step should be unecessary if MinGW is properly added to your PATH
.
- Specify the languages used by the project.
project(Arena LANGUAGES CXX)
Answered By - Romen