无法用CMake指定编译器 [英] Unable to specify the compiler with CMake
问题描述
这个 CMakeLists.txt
文件存在问题:
cmake_minimum_required(VERSION 2.6)
SET(CMAKE_C_COMPILER C:/ MinGW / bin / gcc)
SET(CMAKE_CXX_COMPILER C:/ MinGW / bin / g ++)
项目(cmake_test)
add_executable(a.exe test.cpp)
调用cmake: cmake -GMinGW Makefiles
,它失败,输出如下:
c:\ Users \pietro.mele\projects\tests\buildSystem_test\cmake_test> cmake -GMinGW Makefiles。
- C编译器标识是GNU 4.6.1
- CXX编译器标识是GNU 4.6.1
- 检查工作C编译器:C:/ MinGW / bin / gcc
CMake错误:您的C编译器:C:/ MinGW / bin / gcc找不到。请将CMAKE_C_COMPILER设置为有效的编译器路径或名称。
CMake错误:内部CMake错误,cmake的TryCompile配置失败
- 检查工作的C编译器:C:/ MinGW / bin / gcc - 损坏的
CMake C:/ Program错误文件(x86)/ CMake 2.8 / share / cmake-2.8 / Modules / CMakeTestCCompiler.cmake:52(MESSAGE):
C编译器C:/ MinGW / bin / gcc无法编译一个简单的测试
计划。
CMake将无法正确生成此项目。
调用堆栈(最近调用优先):
CMakeLists.txt:10(项目)
CMake错误:您的C编译器:C:/ MinGW / bin / gcc没找到。请将CMAKE_C_COMPILER设置为有效的编译器路径或名称。
CMake错误:未找到您的CXX编译器:C:/ MinGW / bin / g ++。请将CMAKE_CXX_COMPILER设置为有效的编译器路径或名称。
- 配置不完整,发生错误!
然而, gcc
编译器位于 C:/ MinGW / bin /
并且可以使用。
有什么想法吗?
平台:
- Windows 7
- MinGW / GCC 4.6
不要尝试在CMakeLists.txt文件中设置编译器。
查看关于如何使用不同编译器的CMake FAQ:
http://www.cmake.org/Wiki/CMake_FAQ#How_do_I_use_a_different_compiler.3F
(请注意,您正在尝试方法#3和FAQ说(避免)......)
我们建议避免使用CMakeLists技术,因为在不同的情况下编译器用于第一次配置,然后CMakeLists文件更改为尝试设置不同的编译器...并且因为CMakeLists文件的意图是sho根据运行CMake的开发人员的偏好,可以使用多个编译器。
最好的方法是在调用CMake之前设置环境变量CC和CXX
在CMake检测到要使用的编译器之后,它将它们保存在CMakeCache.txt文件中,以便它甚至可以生成适当的生成系统如果这些变量从环境中消失......
如果您需要更改编译器,则需要从新构建树开始。
I have a problem with this CMakeLists.txt
file:
cmake_minimum_required(VERSION 2.6)
SET(CMAKE_C_COMPILER C:/MinGW/bin/gcc)
SET(CMAKE_CXX_COMPILER C:/MinGW/bin/g++)
project(cmake_test)
add_executable(a.exe test.cpp)
Calling cmake with: cmake -G "MinGW Makefiles"
, it fails with the following output:
c:\Users\pietro.mele\projects\tests\buildSystem_test\cmake_test>cmake -G "MinGW Makefiles" .
-- 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:52 (MESSAGE):
The C compiler "C:/MinGW/bin/gcc" is not able to compile a simple test
program.
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:10 (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!
However the gcc
compiler is in C:/MinGW/bin/
and it works.
Any idea?
Platform:
- Windows 7
- MinGW/GCC 4.6
Never try to set the compiler in the CMakeLists.txt file.
See the CMake FAQ about how to use a different compiler:
http://www.cmake.org/Wiki/CMake_FAQ#How_do_I_use_a_different_compiler.3F
(Note that you are attempting method #3 and the FAQ says "(avoid)"...)
We recommend avoiding the "in the CMakeLists" technique because there are problems with it when a different compiler was used for a first configure, and then the CMakeLists file changes to try setting a different compiler... And because the intent of a CMakeLists file should be to work with multiple compilers, according to the preference of the developer running CMake.
The best method is to set the environment variables CC and CXX before calling CMake for the very first time in a build tree.
After CMake detects what compilers to use, it saves them in the CMakeCache.txt file so that it can still generate proper build systems even if those variables disappear from the environment...
If you ever need to change compilers, you need to start with a fresh build tree.
这篇关于无法用CMake指定编译器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!