我有这个问题 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 -G "MinGW Makefiles"
,它失败并显示以下输出: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!
然而
gcc
编译器在 C:/MinGW/bin/
它有效。任何的想法?
平台:
最佳答案
切勿尝试在 CMakeLists.txt
中设置编译器文件。
请参阅有关如何使用不同编译器的 CMake 常见问题解答:
https://gitlab.kitware.com/cmake/community/wikis/FAQ#how-do-i-use-a-different-compiler
(请注意,您正在尝试方法#3,并且常见问题解答说“(避免)”...)
我们建议避免“在 CMakeLists 中”技术,因为当第一次配置使用不同的编译器时它会出现问题,然后 CMakeLists 文件更改以尝试设置不同的编译器......而且因为 CMakeLists 文件的意图根据运行 CMake 的开发人员的偏好,应该使用多个编译器。
最好的方法是设置环境变量CC
和 CXX
在构建树中第一次调用 CMake 之前。
CMake 检测到要使用的编译器后,会将它们保存在 CMakeCache.txt
中。文件,以便即使这些变量从环境中消失,它仍然可以生成正确的构建系统......
如果您需要更改编译器,则需要从新的构建树开始。
关于gcc - 无法使用 CMake 指定编译器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13054451/