2017-05-07 215 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