Windows 上的 CMake

新手上路,请多包涵

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

原文由 João Abrantes 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 1.8k
2 个回答

因为 CMake 的错误信息在这里具有误导性,所以我认为它需要更详细的答案。

简而言之,您遇到了 鸡与蛋 的问题。

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

  • 你没有给任何 明确的生成器-G 一起使用
  • 它找不到安装的 Visual Studio
  • 它在您的 PATH 环境中找不到任何 C/C++ 编译器
  • 它找不到 CC 使用编译器的完整路径定义的环境变量

它默认为 nmake

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

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

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

  1. cmake.exe -G "MinGW Makefiles" .. 给出正确的发电机选择(正如@Guillaume 链接的答案所暗示的那样)
  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.

参考

原文由 Florian 发布,翻译遵循 CC BY-SA 4.0 许可协议

我使用 cmake -G "MinGW Makefiles" . 而不是 cmake . 它有效!

原文由 Lucky Ning 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题