如何在Windows上设置cmake CXX变量

use*_*307 5 c++ windows cmake

我收到以下错误

正在使用:Microsoft Windows [Versión6.1.7601]

错误:

CMake Warning at CMakeLists.txt:4 (project):
  To use the NMake generator, cmake must be run from a shell that can use the
  compiler cl from the command line.  This environment does not contain
  INCLUDE, LIB, or LIBPATH, and these must be set for the cl compiler to
  work.


-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
CMake Error at CMakeLists.txt:4 (project):
  The CMAKE_C_COMPILER:

    cl

  is not a full path and was not found in the PATH.

  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:4 (project):
  The CMAKE_CXX_COMPILER:

    cl

  is not a full path and was not found in the PATH.

  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!
Run Code Online (Sandbox Code Playgroud)

如果有人可以帮忙...

use*_*167 5

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

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


Mil*_*nek 4

在运行 cmake 之前,您需要运行 Visual Studio 提供的批处理脚本来设置环境。就在下面X:\Visual\Studio\Dir\VC\vcvarsall.bat。开始菜单中还应该有一个“Visual Studio 命令提示符”的快捷方式,它将打开提示符并自动运行vcvarsall.bat.

  • w/ vs2019 开始菜单项似乎是“VS 2019 的开发人员命令提示符” (3认同)