C++ Windows 上的 CMake
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35869564/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
CMake on Windows
提问by Jo?o Abrantes
I am trying to run CMake on Windows, and I get the following error:
我正在尝试在 Windows 上运行 CMake,但出现以下错误:
-- 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.
However my "CC" environment variable is set!
但是我的“CC”环境变量已设置!
>>echo %CC%
C:\Anaconda2\MinGW\x86_64-w64-mingw32\bin\gcc.exe
采纳答案by Florian
Because CMake's error message is misleading here, I think it warrants a little more detailed answer.
因为 CMake 的错误消息在这里具有误导性,我认为它需要更详细的答案。
In short, you ran into a chicken-and-eggkind of a problem.
简而言之,您遇到了鸡与蛋的问题。
CMake's compiler detection is mighty, but since - during the first try -
CMake 的编译器检测功能强大,但由于 - 在第一次尝试期间 -
- you didn't give any explicit generatorto 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
- 你没有提供任何明确的生成器来使用
-G
- 它找不到安装的 Visual Studio
- 它在您的
PATH
环境中找不到任何 C/C++ 编译器 - 它找不到
CC
使用编译器的完整路径定义的环境变量
It was defaulting to nmake
.
它默认为nmake
.
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.
现在问题来了:它确实在它的变量缓存中记住了您的隐式生成器/编译器选择(参见CMAKE_GENERATOR
参考资料CMakeCache.txt
)。如果您安装了多个编译器,这是一个非常有用的功能。
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.
但是,如果您随后声明了CC
环境变量 - 正如错误消息所暗示的那样 - 为时已晚,因为您的生成器的选择在第一次尝试时就被记住了。
I see two possible ways out of this:
我看到了两种可能的方法:
- 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.
- 通过给出正确的选项
cmake.exe -G "MinGW Makefiles" ..
来否决生成器的选择(如@Guillaume 链接的答案所示) - 删除项目的二进制输出目录(包括
CMakeCache.txt
)并cmake.exe ..
在将编译器的bin
文件夹添加到PATH
环境后执行。
References
参考
回答by konchy
How was your cmake installed? If you installed it using cygwin, now try the latest windows version from cmake official siteand set the PATH variable to make sure the right cmake version is used. It worked for me, hope it help you too.
你的cmake是如何安装的?如果您使用 cygwin 安装它,现在尝试从cmake 官方站点获取最新的 Windows 版本并设置 PATH 变量以确保使用正确的 cmake 版本。它对我有用,希望它也能帮助你。