为什么cmake没有找到编译器cl

时间:2017-06-29 15:06:39

标签: c++ compilation cmake

我正在尝试将一组可执行文件安装到运行Windows 10的计算机上,在下载完源代码后,我需要使用cmake编译它们。我下载了最新版本的cmake,并且(在设置了正确的工作目录之后)一直试图在Windows命令提示符下运行以下命令以安装可执行文件:

mkdir build
cd build
cmake ../
make

但是,cmake命令始终产生以下错误,并且无法生成make命令可以使用的任何类型的make文件:

-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
CMake Error at CMakeLists.txt:2 (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.


CMake Error at CMakeLists.txt:2 (project):
  The CMAKE_CXX_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 "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
  to the compiler, or to the compiler name if it is in the PATH.


-- Configuring incomplete, errors occurred!
See also "C:/Users/Hannah/Documents/nupack3.2.0/build/CMakeFiles/CMakeOutput.log".
See also "C:/Users/Hannah/Documents/nupack3.2.0/build/CMakeFiles/CMakeError.log".

我已尝试过很多cmake解决方案,但没有一个能够正常工作。我试图将我的cmake文件夹的bin添加到我的PATH环境变量中,我试图重新安装我的cmake副本,并尝试使用CMake GUI来生成make文件(Running CMake on Windows),并且甚至下载Visual Studio(How to set cmake CXX variable on windows),但因为我没有足够的经验使用CMake GUI或Visual Studio,或者因为有其他问题,所以似乎没有任何工作, cmake ../会产生完全相同的错误。

有人可以为我提供一些替代解决方案来解决这个问题吗?

2 个答案:

答案 0 :(得分:3)

  

下载了二进制文件后,我需要使用cmake

编译它们

这没有任何意义。您下载了 sources 并需要编译它们,或者您下载了二进制文件并且没有其他任何内容需要编译。

如果结果需要编译,则必须安装编译器(例如Visual Studio)。一旦安装了VS,CMake就可以轻松找到它(使用VS发生器时)。

但是,您的错误消息似乎表明使用了NMake生成器,该生成器需要从正确配置用于构建的命令提示符运行。安装Visual Studio时,应该在开始菜单中有开发命令提示的快捷方式。为您的平台启动正确的一个并从那里运行CMake。

答案 1 :(得分:0)

请注意,我已通过将其添加到安装了Visual Studio 2019的PATH环境变量中来解决了该问题:

C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.20.27508\bin\Hostx64\x64