简体   繁体   English

Windows 上的 CMake

[英]CMake on Windows

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

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-egg kind of a problem.简而言之,您遇到了鸡与蛋的问题。

CMake's compiler detection is mighty, but since - during the first try - CMake 的编译器检测功能强大,但由于 - 在第一次尝试期间 -

  • you didn't give any explicit generator to use with -G您没有提供任何与-G一起使用的显式生成器
  • it couldn't find a Visual Studio installed它找不到安装的 Visual Studio
  • it couldn't find any C/C++ compiler in your PATH environment它在您的PATH环境中找不到任何 C/C++ 编译器
  • it couldn't find a CC environment variable defined with the full path to a compiler它找不到使用编译器完整路径定义的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 ).现在问题来了:它确实记住了您在变量缓存中的隐式生成器/编译器选择(请参阅CMAKE_GENERATOR中的CMakeCache.txt )。 What is a very useful feature, if you have multiple compilers installed.如果您安装了多个编译器,这是一个非常有用的功能。

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:我看到了两种可能的方法:

  1. Overrule the generator choice by given the right one with cmake.exe -G "MinGW Makefiles" .. (as the answer linked by @Guillaume suggests)通过使用cmake.exe -G "MinGW Makefiles" .. (如@Guillaume 链接的答案所建议的) 给出正确的选项来cmake.exe -G "MinGW Makefiles" ..生成器的选择
  2. Delete your project's binary output directory (including CMakeCache.txt ) and do cmake.exe .. after you added your compiler's bin folder to your PATH environment.删除项目的二进制输出目录(包括CMakeCache.txt )并在将编译器的bin文件夹添加到PATH环境后执行cmake.exe ..

References参考

I use cmake -G "MinGW Makefiles" .我使用cmake -G "MinGW Makefiles" . instead of cmake .而不是cmake . It worked!有效!

I came across the same problem and what worked for me was:我遇到了同样的问题,对我有用的是:

  1. I installed Visual Studio (following this tutorial ).我安装了 Visual Studio(按照本教程)。
  • You will need to install the 2019 version (it is 2021 now) -- there are a few extra things but it's fine.您将需要安装 2019 版(现在是 2021 年)——还有一些额外的东西,但没关系。 The entire thing is about 6.7 G.整个事情大约是 6.7 G。
  • You don't really need the pip install dlib part and the rest.你真的不需要pip install dlib部分和其余部分。
  1. On the basis of the above tutorial, I added this path to the environment variable ( C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\VC\\Tools\\MSVC\\14.29.30037\\bin\\Hostx64\\x64 . The method of adding paths to the environment variable can also be found in the above tutorial.)在上面教程的基础上,我在环境变量( C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\VC\\Tools\\MSVC\\14.29.30037\\bin\\Hostx64\\x64添加了这个路径。添加环境变量路径的方法也可以在上面的教程中找到。)

How was your cmake installed? 你的cmake是如何安装的? If you installed it using cygwin, now try the latest windows version from cmake official site and set the PATH variable to make sure the right cmake version is used. 如果您使用cygwin安装它,现在尝试cmake官方站点的最新Windows版本并设置PATH变量以确保使用正确的cmake版本。 It worked for me, hope it help you too. 它对我有用,希望它对你也有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM