cmake的编译器问题(Cmake Compiler Issue)

2019-09-28 15:50发布

我想设置cmake使用的是Windows 10使用MinGW 。 我已经包括路径c:/MinGW/bin在我的系统路径和环境路径设置。 我已删除sh.exe从我的路径(虽然我很想能够保持这种可能的话)。

的CMakeLists.txt

cmake_minimum_required(VERSION 3.8)

set(CMAKE_C_COMPILER "C:/MinGW/bin/gcc.exe")
set(CMAKE_CXX_COMPILER "C:/MinGW/bin/gcc.exe")

project (Tutorial)
add_executable(Tutorial tutorial.cpp)

产量

C:\School\athabascua\data structures\ass1>cmake -g "MinGW Makefiles" .
-- The C compiler identification is GNU 5.3.0
-- The CXX compiler identification is GNU 5.3.0
-- Check for working C compiler: C:/MinGW/bin/gcc.exe
CMake Error: Generator: execution of make failed. Make command was: "nmake" "/NOLOGO" "cmTC_b3144\fast"
-- Check for working C compiler: C:/MinGW/bin/gcc.exe -- broken
CMake Error at C:/Program Files/CMake/share/cmake-3.8/Modules/CMakeTestCCompiler.cmake:51 (message):
The C compiler "C:/MinGW/bin/gcc.exe" is not able to compile a simple test
program.

It fails with the following output:

Change Dir: C:/School/athabascua/data structures/ass1/CMakeFiles/CMakeTmp



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



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

看来,GNU编译器被识别,但似乎并没有工作。 任何帮助将非常感激。 我试图避免使用Cygwin ..但几乎可以走这条路在这里秒。

Answer 1:

要解决我遇到的问题,我不得不做两件事情。

  1. 使用命令cmake -G "MinGW Makefiles" . (在Windows资本-G)
  2. 更新我CMakeLists.txt文件中使用的C编译器和g ++ GCC对C ++编译器

的CMakeLists.txt

cmake_minimum_required(VERSION 3.8)

set(CMAKE_C_COMPILER "C:/MinGW/bin/gcc.exe")
set(CMAKE_CXX_COMPILER "C:/MinGW/bin/g++.exe")

project (Tutorial)
add_executable(Tutorial tutorial.cpp)


文章来源: Cmake Compiler Issue