我有一个简单的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。
我做错了什么?
最佳答案
抱歉,编译器似乎没有安装在您指定的位置。另见 here为什么你应该避免在 CMakeLists.txt 中设置编译器
所以我会删除它们,清除 cmake 缓存,在调用 CMake 之前设置环境变量 CC 和 CXX,然后重试。
关于c++ - 如何正确设置 CMakeLists.txt 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15051347/