Dov
Dov

Reputation: 8542

how to get cmake to use the gnu stack of tools under msys2 (mingw)

On Windows 10, with an installed msys2, which is a variant of mingw, I have an installed cmake with the gcc toolchain and all the standard tools like make.

The version of g++ is 6.2 and make is 4.2.1 Both are in the path.

When I build using cmake:

cmake .

it tries to build using nmake and cl. So somehow because I am on windows cmake is trying to use the visual studio toolchain.

export CMAKE_CXX_COMPILER=g++

does not help. The error is:

-- Building for: NMake Makefiles
-- The C compiler identification is unknown
-- The CXX compiler identification is Clang 3.8.0
-- Check for working C compiler: D:/msys64/mingw64/bin/clang++.exe
CMake Error: Generator: execution of make failed. Make command was: "nmake" "/NOLOGO" "cmTC_87e5f\fast"
-- Check for working C compiler: D:/msys64/mingw64/bin/clang++.exe -- broken
CMake Error at D:/msys64/mingw64/share/cmake-3.6/Modules/CMakeTestCCompiler.cmake:61 (message):
  The C compiler "D:/msys64/mingw64/bin/clang++.exe" is not able to compile a
  simple test program.

  It fails with the following output:

   Change Dir: D:/git/CSP/CMakeFiles/CMakeTmp



  Run Build Command:"nmake" "/NOLOGO" "cmTC_87e5f\fast"



  Generator: execution of make failed.  Make command was: "nmake" "/NOLOGO"
  "cmTC_87e5f\fast"





  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 "D:/git/CSP/CMakeFiles/CMakeOutput.log".
See also "D:/git/CSP/CMakeFiles/CMakeError.log".

Upvotes: 1

Views: 2146

Answers (1)

putu
putu

Reputation: 6444

To use MSYS2 toolchain, you need to specify the build system generator explicitly, i.e.

cmake -G 'MSYS Makefiles' .

Additional note, it's a good practice to separate the application . source file and cmake's generated file, e.g.

mkdir build
cd build
cmake -G 'MSYS Makefiles' ..

Upvotes: 2

Related Questions