2013-02-24 93 views
1

我有一个简单的C++测试项目,并写下我的CMakeLists.txt文件如下;如何正确设置CMakeLists.txt文件?

cmake_minimum_required(VERSION 2.8) 

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

project(simpleTest) 
add_executable(main main.cpp) 

当我尝试运行CMake的GUI的一套发生器MinGW的我收到以下错误信息:

The C compiler identification is GNU 4.6.1 
The CXX compiler identification is GNU 4.6.1 
Check for working C compiler: C:/MinGW/bin/gcc 
CMake Error: your C compiler: "C:/MinGW/bin/gcc" was not found. Please set CMAKE_C_COMPILER to a valid compiler path or name. 
CMake Error: Internal CMake error, TryCompile configure of cmake failed 
Check for working C compiler: C:/MinGW/bin/gcc -- broken 
CMake Error at C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/CMakeTestCCompiler.cmake:61 (message): 
    The C compiler "C:/MinGW/bin/gcc" is not able to compile a simple test 
    program. 

    It fails with the following output: 



    CMake will not be able to correctly generate this project. 
Call Stack (most recent call first): 
    CMakeLists.txt:7 (project) 


CMake Error: your C compiler: "C:/MinGW/bin/gcc" was not found. Please set CMAKE_C_COMPILER to a valid compiler path or name. 
CMake Error: your CXX compiler: "C:/MinGW/bin/g++" was not found. Please set CMAKE_CXX_COMPILER to a valid compiler path or name. 
Configuring incomplete, errors occurred! 

我在Windows 7 64位和我确认了CMD是什么; G ++ --version给出G ++(GCC)4.6.1。

我在做什么错?

回答

2

很抱歉,这看起来像编译器没有安装在您指定的位置。另请参阅here为什么你应该避免设置编译器的CMakeLists.txt

所以我删除这些,清除缓存的CMake,CMake的调用之前设置环境变量CC和CXX,然后再试一次。

+0

你是对的没有在CMakeLists.txt中设置编译器,但一再检查编译器安装在我指定的地方。 – Amani 2013-02-24 16:03:10

+0

您是否删除了两行并清除了cmake缓存?此外,我添加到我的答案,你应该尝试设置环境变量,然后再调用cmake – 2013-02-24 16:15:24

1

我认为你的问题在于路径字符串。试试这个:

set(CMAKE_C_COMPILER "C:\\MinGW\\bin\\gcc") 
set(CMAKE_CXX_COMPILER "C:\\MinGW\\bin\\g++") 

或者,你也可以在CMake GUI中设置你的编译器。点击生成后,选择“指定本地编译器”选项并设置或浏览到正确的位置。

+1

问题(因为我发现和从其他建议)不是你指出的,而是事实sh.exe是在我的系统路径。这也可以通过以下事实来证明:如果我将生成器设置为“MSYS Makefiles”,即使没有在CMakeLists.txt文件中设置CMAKE_C_COMPILER或CMAKE_CXX_COMPiLER,它也可以工作。 – Amani 2013-02-26 15:56:15