我有一个简单的C ++测试项目,并编写了我的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。
我做错了什么?
答案 0 :(得分:2)
抱歉,这看起来好像没有安装指定的编译器。另请参阅here为什么要避免在CMakeLists.txt中设置编译器
所以我删除它们,清除cmake缓存,在调用CMake之前设置环境变量CC和CXX并再试一次。
答案 1 :(得分:1)
我认为你的问题在于路径字符串。试试这个:
set(CMAKE_C_COMPILER "C:\\MinGW\\bin\\gcc")
set(CMAKE_CXX_COMPILER "C:\\MinGW\\bin\\g++")
或者,您也可以在CMake GUI中设置编译器。单击“生成”后,选择“指定本机编译器”选项并设置或浏览到正确的位置。