Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make CMake use Mingw-w64 gcc/g++? [duplicate]

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?

like image 782
Leslie Avatar asked Jul 25 '18 00:07

Leslie


People also ask

Does CMake use GCC or G ++?

Usually under Linux, one uses CMake to generate a GNU make file which then uses gcc or g++ to compile the source file and to create the executable.

Is MinGW-w64 better than MinGW?

MinGW-w64 is a improved version which supports both 32bit and 64bit, and some more of the WinAPI (still not all, because thats much work, but more than MinGW). MinGW-w64 only provides their source code, but no binaries to "just use" the compiler.

How do I add MinGW compiler to my path?

In the Windows search bar, type 'settings' to open your Windows Settings. Search for Edit environment variables for your account. Choose the Path variable in your User variables and then select Edit. Select New and add the Mingw-w64 destination folder path to the system path.


1 Answers

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.

like image 67
duddel Avatar answered Nov 09 '22 17:11

duddel