如何使cmake在msys2(mingw)下使用gnu工具堆栈 [英] how to get cmake to use the gnu stack of tools under msys2 (mingw)

查看:117
本文介绍了如何使cmake在msys2(mingw)下使用gnu工具堆栈的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Windows 10上,安装了msys2(这是mingw的一种变体),我安装了带有gcc工具链和所有标准工具(如make)的cmake.

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.

g ++的版本是6.2,make的版本是4.2.1.两者都在路径中.

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

当我使用cmake进行构建时:

When I build using cmake:

cmake .

它尝试使用nmake和cl进行构建.之所以如此,是因为我在Windows上cmake试图使用Visual Studio工具链.

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++

没有帮助.错误是:

-- 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".

推荐答案

要使用MSYS2工具链,您需要明确指定构建系统生成器,即

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

cmake -G 'MSYS Makefiles' .

补充说明,分离应用程序是一个好习惯.源文件和 cmake 的生​​成文件,例如

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' ..

这篇关于如何使cmake在msys2(mingw)下使用gnu工具堆栈的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆