2017-05-07 213 views
0

我正在尝试使用Windows 10使用MinGW来设置cmake。我已将路径c:/MinGW/bin包含在我的系统路径和环境路径设置中。我从我的路径中删除了sh.exe(尽管如果可能,我希望能够保留这一点)。Cmake编译器问题

的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 ..但几乎准备好在这里在一秒内走这条路线。

+1

它看起来像cmake配置为微软的工具链,因为它试图运行'nmake'。 –

+0

好吧,也许这是因为我使用Visual Studio代码,我会考虑安装nmake。感谢输入 – SuperVeetz

+2

我宁愿建议告诉cmake使用GNU make而不是MS nmake。尝试'cmake -G“MinGW Makefiles”'而不是'cmake -G“NMake Makefiles”'参见https://cmake.org/Wiki/CMake_Generator_Specific_Information#Makefile_generators –

回答

1

要解决我遇到的问题,我必须做两件事。

  1. 使用命令cmake -G "MinGW Makefiles" .(在Windows资本-G)
  2. 更新我的CMakeLists.txt文件来使用gcc的C编译器和g ++中的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) 
+0

Yeah'gcc'和'g ++'都运行相同的编译器,但具有不同的默认选项。对于链接步骤,这些文件全部命名为“* .o”,因此文件名不会提示应该使用C++库。 –

+1

仅供参考,您可以避免在CMakeLists.txt中设置变量,从而保持程序的可移植性,而不必在命令行中指定它们:-DCMAKE_C_COMPILER =“C:/MinGW/bin/gcc.exe”-DCMAKE_CXX_COMPILER =“C :/ MinGW的/ bin中/克++ EXE“'。 – dlasalle