2

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.

8
  • 1
    It looks like cmake is configured for Microsoft's toolchain, because it's trying to run nmake. Commented May 7, 2017 at 22:22
  • okay, maybe this is because i'm using Visual Studio Code, i will look into installing nmake. Thanks for the input Commented May 7, 2017 at 22:29
  • 3
    I would rather suggest telling cmake to use GNU make instead of MS nmake. Try cmake -G"MinGW Makefiles" instead of cmake -G"NMake Makefiles" See cmake.org/Wiki/… Commented May 7, 2017 at 22:30
  • 2
    Or in VS Code, set cmake.generator as shown here, but use MinGW Makefiles Commented May 7, 2017 at 22:35
  • Thank you Ben. It is compiling now. The problem was that I was using cmake -g "MinGW Makefiles" and having a lowercase -g seemed to cause the problem because when I use uppercase -G it works. Good ol windows Commented May 7, 2017 at 22:37

1 Answer 1

5

To fix the problem I was having, I had to do two things.

  1. use the command cmake -G "MinGW Makefiles" . (capital -G on windows)
  2. 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)
Sign up to request clarification or add additional context in comments.

2 Comments

Yeah gcc and g++ both run the same compiler, but with different default options. And for the link step, the files are all named *.o so the filename provides no hint that C++ libraries should be used.
Just FYI, you can avoid setting the variables in the CMakeLists.txt and thus keep your program portable by instead specifying them on the command line -DCMAKE_C_COMPILER="C:/MinGW/bin/gcc.exe" -DCMAKE_CXX_COMPILER="C:/MinGW/bin/g++.exe".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.