为什么Cmake找不到编译器CL

Why is cmake not finding the compiler cl

本文关键字:CL 编译器 找不到 Cmake 为什么      更新时间:2023-10-16

我试图将一组可执行文件安装到运行Windows 10的计算机上,然后下载了源后,我需要使用CMAKE对其进行编译。我下载了最新版本的Cmake,(设置了适当的工作目录后(一直在尝试在Windows命令提示符上运行以下命令,以安装可执行文件:

mkdir build
cd build
cmake ../
make

但是,cmake命令始终产生以下错误,并且无法生成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文件夹的垃圾箱添加到我的路径环境变量中,我试图重新安装我的Cmake副本,并尝试使用CMAKE GUI以生成Make File(在Windows上运行CMAKE(,甚至甚至是下载Visual Studio(如何在Windows上设置CMAKE CXX变量(,但是因为我没有使用CMake GUI或Visual Studio的经验,或者因为有问题出现问题,似乎根本没有用,所以cmake ../产生完全相同的错误。

有人可以为我提供一些如何使此命令起作用的替代解决方案?

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

对它们进行编译

这是没有意义的。您要么下载了来源需要编译它们,要么下载了 binaries ,而无需编译其他任何内容。

如果您需要编译,则必须安装编译器(例如Visual Studio(。安装了VS后,CMAKE应该毫不费力地找到它(使用VS Generator时(。

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

请注意,我通过安装了Visual Studio 2019的PATH环境变量解决了问题:

C:Program Files (x86)Microsoft Visual Studio2019ProfessionalVCToolsMSVC14.20.27508binHostx64x64