【问题标题】:CMake on WindowsWindows 上的 CMake
【发布时间】:2016-06-22 12:39:44
【问题描述】:

我尝试在 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.

但是我的“CC”环境变量被设置了!

>>echo %CC%
C:\Anaconda2\MinGW\x86_64-w64-mingw32\bin\gcc.exe

【问题讨论】:

  • Running CMake on Windows的可能重复
  • 您可以拨打您正在使用的cmake.exe ... 电话吗?一种猜测是 C:\Anaconda2\MinGW\x86_64-w64-mingw32\bin 不是您的 PATH 环境变量的一部分(如错误消息所示)。另请参阅here。
  • @Florian 只是正常的调用:“cmake ..”。是的,它不是我的PATH 的一部分,错误说:通过将环境变量“CC”或 CMake 缓存条目 CMAKE_C_COMPILER 设置为编译器的完整路径或编译器名称,告诉 CMake 在哪里可以找到编译器在 PATH 中。”所以我的 CC 指向完整路径,而不仅仅是名称.. 应该没有任何问题
  • @JoãoAbrantes 您还必须将 MinGW 二进制目录添加到 PATH,因为 gcc.exe 确实依赖于该目录中的 DLL。如果我在the Dependency Walker application 中查看我的gcc.exe,我会得到例如对LIBWINPTHREAD-1.DLL的引用。
  • @Florian 好的,我现在已将 MinGW 二进制目录添加到 PATH。但是错误仍然存​​在:(

标签: c++ c cmake


【解决方案1】:

由于 CMake 的错误消息在这里具有误导性,我认为它需要更详细的答案。

简而言之,您遇到了chicken-and-egg 之类的问题。

CMake 的编译器检测功能强大,但因为 - 在第一次尝试时 -

  • 您没有提供任何explicit generator 与-G 一起使用
  • 找不到安装的 Visual Studio
  • 在您的 PATH 环境中找不到任何 C/C++ 编译器
  • 找不到使用编译器完整路径定义的 CC 环境变量

它默认为nmake。

现在问题来了:它确实记住了您在变量缓存中的隐式生成器/编译器选择(参见CMakeCache.txt 中的CMAKE_GENERATOR)。如果您安装了多个编译器,这是一个非常有用的功能。

但是,如果您随后声明 CC 环境变量 - 正如错误消息所暗示的那样 - 为时已晚,因为您的生成器的选择在第一次尝试时就被记住了。

我看到了两种可能的方法:

  1. 用cmake.exe -G "MinGW Makefiles" .. 给出正确的生成器选择(正如@Guillaume 链接的答案所暗示的那样)
  2. 将编译器的bin 文件夹添加到PATH 环境后,删除项目的二进制输出目录(包括CMakeCache.txt)并执行cmake.exe ..。

参考文献

【讨论】:

  • 我添加了路径 C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.15.26726\bin\Hostx64\x64 并且它有效。 cl 未添加到路径中
【解决方案2】:

我使用cmake -G "MinGW Makefiles" . 而不是cmake . 成功了!

【讨论】:

    【解决方案3】:

    我遇到了同样的问题,对我有用的是:

    1. 我安装了 Visual Studio(在 this tutorial 之后)。
    • 您将需要安装 2019 版本(现在是 2021)——还有一些额外的东西,但没关系。整个东西大约是 6.7 G。
    • 您实际上并不需要 pip install dlib 部分和其他部分。
    1. 在上面教程的基础上,我在环境变量中加入了这个路径( C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30037\bin\Hostx64\x64。添加环境变量路径的方法也可以参考上面的教程。)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-10-07
      • 2017-10-05
      • 1970-01-01
      • 1970-01-01
      • 2011-05-05
      • 1970-01-01
      • 2015-06-12
      • 2018-10-23
      相关资源
      最近更新 更多