cmake:指定编译器的问题(2) [英] cmake: problems specifying the compiler (2)

查看:529
本文介绍了cmake:指定编译器的问题(2)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对此 CMakeLists.txt 文件有问题:

  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)

调用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错误,TryCompile配置cmake失败
- 检查工作C编译器:C:/ MinGW / bin / gcc - broken
CMake Error at C:/ Program文件(x86)/ CMake 2.8 / share / cmake-2.8 / Modules / CMakeTestCCompiler.cmake:52(MESSAGE):
C编译器C:/ MinGW / bin / gcc无法编译一个简单的测试
程序。

CMake将无法正确生成此项目。
调用堆栈(最近调用):
CMakeLists.txt:10(project)

CMake错误:你的C编译器:C:/ MinGW / bin / gcc没找到。请将CMAKE_C_COMPILER设置为有效的编译器路径或名称。
CMake错误:您的CXX编译器:C:/ MinGW / bin / g ++未找到。请将CMAKE_CXX_COMPILER设置为有效的编译器路径或名称。
- 配置不完整,发生错误!

但是 gcc 任何想法?


$ b


$ b $ b

平台:




  • Windows 7

  • MinGW / GCC 4.6


解决方案

不要尝试在CMakeLists.txt文件中设置编译器。



有关如何使用不同编译器的CMake常见问题:



http://www.cmake.org/Wiki/CMake_FAQ#How_do_I_use_a_different_compiler.3F



(请注意,您正在尝试方法#3和常见问题说(避免)...)



我们建议避免使用在CMakeLists技术,编译器用于第一次配置,然后CMakeLists文件更改尝试设置不同的编译器...并且因为CMakeLists文件的意图应该是与多个编译器,根据运行CMake的开发人员的喜好的偏好。 / p>

最好的方法是在构建树中第一次调用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:指定编译器的问题(2)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆