【问题标题】:how to get cmake to use the gnu stack of tools under msys2 (mingw)如何让 cmake 使用 msys2 (mingw) 下的 gnu 工具堆栈
【发布时间】:2018-04-13 02:59:28
【问题描述】:

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

g++的版本是6.2,make是4.2.1都在路径里。

当我使用 cmake 构建时:

cmake .

它尝试使用 nmake 和 cl 构建。所以不知何故因为我在 Windows 上 cmake 正在尝试使用 Visual Studio 工具链。

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

【问题讨论】:

    标签: c++ cmake


    【解决方案1】:

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

    cmake -G 'MSYS Makefiles' .
    

    附加说明,分离应用程序是一个好习惯。源文件和cmake的生成文件,例如

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

    【讨论】:

    • 仍然得到一个错误:# error "The CMAKE_C_COMPILER is set to a C++ compiler" export CMAKE_C_COMPILER=clang 没有帮助。任何建议
    • 您是否同时安装了gccg++
    • 另外,MSYS2 带有三个终端,MSYS,32 位和 64 位。您在哪个终端执行了cmake 命令?它还有三个cmake版本(mingw-w64-i686-cmakemingw-w64-x86_64-cmakemsys/cmake),你安装的是哪一个?
    • 如果需要显式指定编译器,在执行cmake时加上-D CMAKE_C_COMPILER=gcc
    • 在路径中,g++ 6.2版以及clang++,一切都是w64-x86_64
    猜你喜欢
    • 1970-01-01
    • 2016-10-29
    • 2019-01-01
    • 2015-03-26
    • 1970-01-01
    • 2023-04-08
    • 2010-10-28
    • 2021-10-23
    相关资源
    最近更新 更多