Using Ninja as a generator with MSYS2 + MinGW on Windows 10 x64

Viewed 2163

I am using MSYS2 + MinGW x64 + CMake as my development setup on windows. Currently, to initialize my projects, I open a "MSYS2 MinGW 64-bit" shell and invoke CMake as follows:

cmake .. -G"MinGW Makefiles"

This works nicely, but I'd like to use ninja instead of make. Therefore, I installed mingw-w64-x86_64-ninja via my MSYS2 shell, making it available in my MinGW environment. I expected

cmake .. -G"Ninja"

to work, but instead it fails with the following errors:

-- The C compiler identification is GNU 10.2.0
-- The CXX compiler identification is GNU 10.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: C:/msys64/mingw64/bin/gcc.exe
-- Check for working C compiler: C:/msys64/mingw64/bin/gcc.exe - broken
CMake Error at C:/msys64/mingw64/share/cmake-3.20/Modules/CMakeTestCCompiler.cmake:66 (message):
  The C compiler

    "C:/msys64/mingw64/bin/gcc.exe"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: C:/projecct/build/CMakeFiles/CMakeTmp

    Run Build Command(s):C:/msys64/usr/bin/ninja.exe cmTC_c3f3d && [1/2] Building C object CMakeFiles/cmTC_c3f3d.dir/testCCompiler.c.obj
    FAILED: CMakeFiles/cmTC_c3f3d.dir/testCCompiler.c.obj
    C:\msys64\mingw64\bin\gcc.exe    -o CMakeFiles/cmTC_c3f3d.dir/testCCompiler.c.obj -c testCCompiler.c
    /bin/sh: line 1: C:msys64mingw64bingcc.exe: command not found
    ninja: build stopped: subcommand failed.





  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:2 (project)


-- Configuring incomplete, errors occurred!
See also "C:/project/build/CMakeFiles/CMakeOutput.log".
See also "C:/project/build/CMakeFiles/CMakeError.log".

Judging from the following line

 /bin/sh: line 1: C:msys64mingw64bingcc.exe: command not found

it seems that this is a / vs \ issue.

  • Is there a solution or workaround to this problem?

  • Can I use Ninja as my generator on a MSYS2 + MinGW x64 setup on Windows 10?

2 Answers

In my company we use mingw64 + ninja on windows 10 on a daily basis. I am not sure what is going wrong in your setup, here's a few tips:

  • Run cmake from the mingw64 shell, not the msys2 shell (usually C:/msys64/mingw64.exe)
  • Make sure you installed mingw-w64-x86_64-cmake, not just cmake or mingw-w64-cmake.
  • Make sure you installed mingw-w64-x86_64-ninja, not just ninja or mingw-w64-ninja.

With these 2 items in mind, on my windows 10 machine I can configure and compile with ninja successfully (granted our setup is a bit old, we froze a msys2 version from a couple of years ago).

same problem

pacman -R ninja
pacman -S mingw-w64-x86_64-ninja

resolved - wrong ninja!

Related