我正在尝试在 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:Anaconda2MinGWx86_64-w64-mingw32ingcc.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
PATH
环境中找不到任何 C/C++ 编译器CC
环境变量-G
PATH
environmentCC
environment variable defined with the full path to a compiler默认为nmake
.
现在问题来了:它确实记住了您在其变量缓存中的隐式生成器/编译器选择(请参阅CMakeCache.txt
中的CMAKE_GENERATOR
).如果您安装了多个编译器,这是一个非常有用的功能.
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
文件夹后执行cmake.exe ..
到您的 PATH
环境.cmake.exe -G "MinGW Makefiles" ..
(as the answer linked by @Guillaume suggests)CMakeCache.txt
) and do cmake.exe ..
after you added your compiler's bin
folder to your PATH
environment.参考资料
这篇关于Windows 上的 CMake的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!