在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 

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

简而言之,你遇到了一个鸡蛋和鸡蛋的问题。

CMake的编译器检测很强大,但是从第一次尝试开始 –

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

它是默认的nmake

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

但是如果你然后声明CC环境变量 – 正如错误消息所暗示的那样 – 那么为时已晚,因为你的选择器在第一次尝试中被记住了。

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

  1. 通过使用cmake.exe -G "MinGW Makefiles" ..给出正确的选项来cmake.exe -G "MinGW Makefiles" ..发生器选择cmake.exe -G "MinGW Makefiles" .. (由@Guillaume建议链接的答案)
  2. 将编译器的bin文件夹添加到PATH环境后,删除项目的二进制输出目录(包括CMakeCache.txt )并执行cmake.exe ..

参考

  • 在Windows上运行CMake
  • Windows中CMake的默认生成器是什么?
  • CMakeLists.txt上的CMake错误:30(项目):找不到CMAKE_C_COMPILER
  • CMake:如何指定要使用的Visual C ++版本?

你的cmake是如何安装的? 如果你使用cygwin安装它,现在尝试cmake官方网站的最新windows版本并设置PATH变量以确保使用正确的cmake版本。 它对我有用,希望它对你也有帮助。