2

我有一个简单的 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。

我究竟做错了什么?

4

2 回答 2

3

抱歉,这看起来编译器未安装在您指定的位置。另请参阅此处为什么应避免在 CMakeLists.txt 中设置编译器

所以我会删除这些,清除 cmake 缓存,在调用 CMake 之前设置环境变量 CC 和 CXX,然后重试。

于 2013-02-24T15:50:17.193 回答
1

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

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

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

于 2013-02-26T12:16:49.640 回答