Windows上的CMake [英] CMake on Windows
问题描述
我试图在Windows上运行CMake,但出现以下错误:
I am trying to run CMake on Windows, and I get the following error:
-- The C compiler identification is unknown
CMake Error at CMakeLists.txt:3 (PROJECT):
The CMAKE_C_COMPILER:
cl
is not a full path and was not found in the PATH.
To use the NMake generator with Visual C++, cmake must be run from a shell
that can use the compiler cl from the command line. This environment is
unable to invoke the cl compiler. To fix this problem, run cmake from the
Visual Studio Command Prompt (vcvarsall.bat).
Tell CMake where to find the compiler by setting either the environment
variable "CC" or the CMake cache entry CMAKE_C_COMPILER to the full path to
the compiler, or to the compiler name if it is in the PATH.
但是设置了我的 CC环境变量!
However my "CC" environment variable is set!
>>echo %CC%
C:\Anaconda2\MinGW\x86_64-w64-mingw32\bin\gcc.exe
推荐答案
由于CMake的错误消息在这里令人误解,我认为它值得
Because CMake's error message is misleading here, I think it warrants a little more detailed answer.
总之,您遇到了鸡和蛋有点问题。
In short, you ran into a chicken-and-egg kind of a problem.
CMake的编译器检测能力很强,但由于-在第一次尝试中-
CMake's compiler detection is mighty, but since - during the first try -
- 您没有提供任何显式生成器与
-G
- 一起使用安装了Visual Studio
- 在您的
PATH
环境中找不到任何C / C ++编译器 - 找不到
CC
环境变量定义了编译器的完整路径
- you didn't give any explicit generator to use with
-G
- it couldn't find a Visual Studio installed
- it couldn't find any C/C++ compiler in your
PATH
environment - it couldn't find a
CC
environment variable defined with the full path to a compiler
默认值为 nmake
。
现在出现了问题:它确实记住了变量缓存中的隐式生成器/编译器选择(请参见 CMAKE_GENERATOR
在 CMakeCache.txt
中)。如果您安装了多个编译器,这是一个非常有用的功能。
Now here comes the problem: it does remember your implicit generator/compiler choice in it's variable cache (see CMAKE_GENERATOR
in CMakeCache.txt
). What is a very useful feature, if you have multiple compilers installed.
但是如果您随后声明 CC
环境变量-如错误消息所示-太迟了,因为第一次尝试时记住了生成器的选择。
But if you then declare the CC
environment variable - as the error message suggests - it's too late since your generator's choice was remembered in the first try.
我看到了两种可能的解决方法:
I see two possible ways out of this:
- 使用
cmake.exe -G MinGW Makefiles ..
(如@Guillaume链接的答案所建议的那样) - 删除项目的二进制输出目录(包括
CMakeCache.txt
)并执行将编译器的bin
文件夹添加到PATH $之后,
cmake.exe ..
c $ c>环境。
- Overrule the generator choice by given the right one with
cmake.exe -G "MinGW Makefiles" ..
(as the answer linked by @Guillaume suggests) - Delete your project's binary output directory (including
CMakeCache.txt
) and docmake.exe ..
after you added your compiler'sbin
folder to yourPATH
environment.
参考文献
- 在Windows上运行CMake
- Windows中CMake的默认生成器是什么?
- CMake错误位于CMakeLists.txt:30(项目):找不到CMAKE_C_COMPILER
- CMake:如何指定要使用的Visual C ++版本?
- Running CMake on Windows
- What is the default generator for CMake in Windows?
- CMake error at CMakeLists.txt:30 (project): No CMAKE_C_COMPILER could be found
- CMake: how to specify the version of Visual C++ to work with?
这篇关于Windows上的CMake的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!