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
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)
You need to designate your compiler in the CMakeList.txt file:
set(CMAKE_C_COMPILER <your c path >)
set(CMAKE_CXX_COMPILER <your c++ path here>)
Related
I've been trying to compile my code with CMake using the "MSYS Makefiles" generator. I wrote the following command:
cmake -S . -B build/ -G "MSYS Makefiles
But I was presented with the following error:
CMake Error: CMake was unable to find a build program corresponding to "MSYS 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 "MSYS 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
CMake Error: CMAKE_AR was not found, please set to archive program.
After some investigation, I found that I had to install something called "mingw-make" to do this. Apparently this "mingw-make" can be installed in the "MinGW gui". Note that I checked if I already have "mingw-make" installed and I don't.
I'm confused because I can't seem to find this "MinGW gui" anywhere. I installed MinGW, and only have an application on my computer called "Modify or Remove MinGW". I searched the install options, and couldn't find "mingw-make" anywhere.
Where can I download this "mingw-make" from? Thanks.
Use mingw32-make only with cmake -G"MinGW Makefiles".
Use make only with cmake -G"MSYS Makefiles".
But if you want the best performance you should get Ninja and use ninja with cmake -G"Ninja".
MinGW is all command line, though there are some GUI installers for it. MinGW-w64 is the successor to MinGW which also supports 64-bit Windows.
There are standalone MinGW-w64 Windows releases available from https://winlibs.com/ that don't require installation steps, just extract. This also includes mingw32-make
Asked this question:
CMake cannot indentify path to compiler mentioned by set(CMAKE_C_COMPILER "path") rule
received an incorrect rules order response(it was obviously correct).
Aplied changes and tried again:
cmake .
output:
-- The C compiler identification is GNU 9.2.0
-- The CXX compiler identification is GNU 9.2.0
-- Check for working C compiler: C:/Strawberry/c/bin/gcc.exe
CMake Error: Generator: execution of make failed. Make command was: nmake /nologo cmTC_fc6d3\fast &&
-- Check for working C compiler: C:/Strawberry/c/bin/gcc.exe - broken
But I need not nmake but mingw make file ,found this topic:
CMake Error : execution of make failed on Windows
The 100% same problem I have .Tried provided solution:
You need to specify a generator in CMake command line like -G "MinGW
Makefiles" and - depending on how many compilers you have installed -
also the full paths to the compilers.
cmake -G "MinGW Makefiles"
output:
CMake Warning:
No source or binary directory provided. Both will be assumed to be the
same as the current working directory, but note that this warning will
become a fatal error in future CMake releases.
CMake Error: Error: generator : MinGW Makefiles
Does not match the generator used previously: NMake Makefiles
Either remove the CMakeCache.txt file and CMakeFiles directory or choose a different binary directory.
and next cmake . output gives (after deleting CMakeCache.txt file and CMakeFiles directory as mentioned above):
-- The C compiler identification is GNU 9.2.0
-- The CXX compiler identification is GNU 9.2.0
-- Check for working C compiler: C:/Strawberry/c/bin/gcc.exe
CMake Error: CMake was unable to find a build program corresponding to "NMake 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 at C:/Program Files/CMake/share/cmake-3.17/Modules/CMakeTestCCompiler.cmake:44 (try_compile):
Failed to configure test project build system.
Call Stack (most recent call first):
CMakeLists.txt:9 (project)
-- Configuring incomplete, errors occurred!
See also "CMakeFiles/CMakeOutput.log".
CMake Error: Generator: execution of make failed. Make command was: cmTC_4b6e5/fast &&
-- Check for working C compiler: C:/Strawberry/c/bin/gcc.exe - broken
The 3 things i cannot understand:
How to ... specify ... the full paths to the compilers or needed source or binary directory.
Why compilers are connected to make.exe in any way.
Why CMAKE_MAKE_PROGRAM is not set if there is proper rule.
Changing rules order :
set( CMAKE_MAKE_PROGRAM FORCE ) set(CMAKE_C_COMPILER ) set(CMAKE_CXX_COMPILER ) and
set(CMAKE_C_COMPILER ) set(CMAKE_CXX_COMPILER ) set( CMAKE_MAKE_PROGRAM FORCE ) has the same result after call.
If I remove set( CMAKE_MAKE_PROGRAM ) rule configuring with CMake GUI is possible but with cmd manual cmake . call is not .Same output as provided above.
Inside CMakeCache.txt generated by CMake GUI call's are lines :
//Path to a program.
CMAKE_MAKE_PROGRAM:FILEPATH=C:/Strawberry/c/bin/mingw32-make.exe
so for it was possible to find mingw32-make.exe and path provided for manual call is also right.
My CMakeLists.txt:
cmake_minimum_required(VERSION 3.17.1)
#set(CMAKE_MAKE_PROGRAM C:/Strawberry/c/bin/make.exe FORCE )
set( CMAKE_MAKE_PROGRAM C:/Strawberry/c/bin/mingw32-make.exe FORCE )
set(CMAKE_C_COMPILER "C:/Strawberry/c/bin/gcc.exe")
set(CMAKE_CXX_COMPILER "C:/Strawberry/c/bin/g++.exe")
project("Client")
enable_testing()
set(CMAKE_CXX_FLAGS "-std=c++17 " )
add_executable(Client
main.cpp
client.cpp
client.h
logmsg.cpp
includes.h
)
target_link_libraries(Client wsock32 ws2_32)
add_test(NAME test COMMAND Client )
I am using CLion to write C++ programs and I am using MinGW.But I have some files missing namely-Make,C Compiler and C++ Compiler which are not found.I am using MinGW Installation Manager to install the packages but I don't know the exact names of the packages I have to install.
What are the names of the packages I need to install to get rid of this error?(I need the specific names that I can get in the MinGW Installation manager.)
I am also getting these error messages-
"C:\Program Files\JetBrains\CLion 2017.1.2\bin\cmake\bin\cmake.exe" -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - MinGW Makefiles"
C:\Users\Lenovo\CLionProjects\untitled
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
-- Configuring incomplete, errors occurred!
Thanks for any help!!
tps://i.stack.imgur.com/SFWFU.png
Under the "Basic Setup" category in the installer, you need to select and install mingw32-gcc-g++ and mingw32-make.
I am trying to setup cmake using Windows 10 using MinGW. I have included the path c:/MinGW/bin in my system path and environment path settings. I have removed sh.exe from my path (although, i would love to be able to keep this if possible).
CMakeLists.txt
cmake_minimum_required(VERSION 3.8)
set(CMAKE_C_COMPILER "C:/MinGW/bin/gcc.exe")
set(CMAKE_CXX_COMPILER "C:/MinGW/bin/gcc.exe")
project (Tutorial)
add_executable(Tutorial tutorial.cpp)
Output
C:\School\athabascua\data structures\ass1>cmake -g "MinGW Makefiles" .
-- The C compiler identification is GNU 5.3.0
-- The CXX compiler identification is GNU 5.3.0
-- Check for working C compiler: C:/MinGW/bin/gcc.exe
CMake Error: Generator: execution of make failed. Make command was: "nmake" "/NOLOGO" "cmTC_b3144\fast"
-- Check for working C compiler: C:/MinGW/bin/gcc.exe -- broken
CMake Error at C:/Program Files/CMake/share/cmake-3.8/Modules/CMakeTestCCompiler.cmake:51 (message):
The C compiler "C:/MinGW/bin/gcc.exe" is not able to compile a simple test
program.
It fails with the following output:
Change Dir: C:/School/athabascua/data structures/ass1/CMakeFiles/CMakeTmp
Run Build Command:"nmake" "/NOLOGO" "cmTC_b3144\fast"
Generator: execution of make failed. Make command was: "nmake" "/NOLOGO"
"cmTC_b3144\fast"
It seems that the GNU compilers are identified but don't seem to work. Any help would be much appreciated. I am trying to avoid using Cygwin.. but almost ready to go that route in a sec here.
To fix the problem I was having, I had to do two things.
use the command cmake -G "MinGW Makefiles" . (capital -G on windows)
update my CMakeLists.txt file to use gcc for C compiler and g++ for C++ compiler
CMakeLists.txt
cmake_minimum_required(VERSION 3.8)
set(CMAKE_C_COMPILER "C:/MinGW/bin/gcc.exe")
set(CMAKE_CXX_COMPILER "C:/MinGW/bin/g++.exe")
project (Tutorial)
add_executable(Tutorial tutorial.cpp)
I have a simple C++ test project and wrote my CMakeLists.txt file as follows;
cmake_minimum_required(VERSION 2.8)
set(CMAKE_C_COMPILER "C:/MinGW/bin/gcc")
set(CMAKE_CXX_COMPILER "C:/MinGW/bin/g++")
project(simpleTest)
add_executable(main main.cpp)
When i try to run CMake GUI an set generator to MinGW i get the following error message:
The C compiler identification is GNU 4.6.1
The CXX compiler identification is GNU 4.6.1
Check for working C compiler: C:/MinGW/bin/gcc
CMake Error: your C compiler: "C:/MinGW/bin/gcc" was not found. Please set CMAKE_C_COMPILER to a valid compiler path or name.
CMake Error: Internal CMake error, TryCompile configure of cmake failed
Check for working C compiler: C:/MinGW/bin/gcc -- broken
CMake Error at C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/CMakeTestCCompiler.cmake:61 (message):
The C compiler "C:/MinGW/bin/gcc" is not able to compile a simple test
program.
It fails with the following output:
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:7 (project)
CMake Error: your C compiler: "C:/MinGW/bin/gcc" was not found. Please set CMAKE_C_COMPILER to a valid compiler path or name.
CMake Error: your CXX compiler: "C:/MinGW/bin/g++" was not found. Please set CMAKE_CXX_COMPILER to a valid compiler path or name.
Configuring incomplete, errors occurred!
I'm on Windows 7 64 bit and i confirmed on cmd that;
G++ --version gives G++ (GCC) 4.6.1.
What am I doing wrong?
Sorry but this looks like the compiler is not installed where you specified. Also see here why you should avoid setting the compiler in CMakeLists.txt
So I'd remove those, clear the cmake cache, set the environment variables CC and CXX before calling CMake and try again.
I think your problem lies in the path string. Try this:
set(CMAKE_C_COMPILER "C:\\MinGW\\bin\\gcc")
set(CMAKE_CXX_COMPILER "C:\\MinGW\\bin\\g++")
Alternatively, you can also set your compilers in the CMake GUI. After you click on generate, choose the option "Specify native compilers" and set or browse to the correct location.