16

I am on Windwos trying to get Mingw-w64 to work with CMake since my MSVC is somehow not working at all (using Windows10 64bit.

Basically I add the arguments -DCMAKE_CXX_COMPILER="C:/MinGW-w64/mingw64/bin/g++.exe" -DCMAKE_C_COMPILER="C:/MinGW-w64/mingw64/bin/gcc.exe" to my call to CMake which sets the corresponding compiler.

However I get these errors:

-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
-- Check for working C compiler: C:/MinGW-w64/mingw64/bin/gcc.exe
-- Check for working C compiler: C:/MinGW-w64/mingw64/bin/gcc.exe -- broken
CMake Error at C:/Program Files/CMake/share/cmake-3.12/Modules/CMakeTestCCompiler.cmake:52 (message):
  The C compiler

    "C:/MinGW-w64/mingw64/bin/gcc.exe"

  is not able to compile a simple test program.

How could I get this to work?

Leslie
  • 333
  • 1
  • 3
  • 12
  • Can you launch *"C:/MinGW-w64/mingw64/bin/gcc.exe"* (e.g. from *cmd*)? You might also want to try the *Win* path style: *"C:\MinGW-w64\mingw64\bin\gcc.exe"* (if that doesn't work either you could tye doubling the "**\\**"s) – CristiFati Jul 27 '18 at 20:51
  • 1
    Also you want to add *C:\MinGW-w64\mingw64\bin* in *%PATH%*. – CristiFati Jul 27 '18 at 21:00

1 Answers1

35

The simplest way to generate makefiles for MinGW (and MinGW-w64) is to use the appropriate CMake generator. Just call cmake with

-G "MinGW Makefiles"

no need to set DCMAKE_CXX_COMPILER and DCMAKE_C_COMPILER by hand.

For this to work, CMake must find your compilers. So this path must be added to the windows PATH variable, as CristiFati pointed out:

C:/MinGW-w64/mingw64/bin

To check if the PATH is correct, fire up a Windows command prompt and run

where gcc

The output should be (at least) the path you just added to the Windows PATH variable.

duddel
  • 751
  • 9
  • 13
  • 1
    You hadditionally have to specify CMAKE_MAKE_PROGRAM to mingw32-make – sancelot Aug 21 '19 at 07:11
  • 1
    we specifically want to use mingw64, isn't that contradictory to set the make programe to mingw32? am I missing something? – Patafikss May 26 '21 at 15:10
  • 4
    @Patafikss somewhat confusingly, mingw64 is invoked by calling mingw32. mingw32 is used to compile both 32-bit and 64-bit binaries. – Catradora May 26 '21 at 18:53
  • 1
    @sancelot you can make a batch program called make.bat that refer to mingw32-make.exe. Place this batch program in the MinGW bin folder. See [Calling an executable by a different name](https://stackoverflow.com/questions/4120840/calling-an-executable-by-a-different-name/11349488#11349488) – AndreGraveler Mar 14 '22 at 04:18