C++ 如何在 Windows 上设置 cmake CXX 变量

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31629966/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 14:00:30  来源:igfitidea点击:

How to set cmake CXX variable on windows

c++windowscmake

提问by user3808307

I am getting the following error

我收到以下错误

Working on: Microsoft Windows [Versión 6.1.7601]

正在处理:Microsoft Windows [版本 6.1.7601]

ErrorS:

错误:

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!

If somone can help...

如果有人可以帮助...

回答by Miles Budnek

You need to run the batch script provided by Visual Studio to set up your environment before running cmake. It's under X:\Visual\Studio\Dir\VC\vcvarsall.bat. There should also be a shortcut in the start menu for "Visual Studio Command Prompt" that will open a prompt and automatically run vcvarsall.bat.

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

回答by user8128167

Please note that I resolved the problem by adding this to my PATH environment variable where I have Visual Studio 2019 installed:

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

C:\Program Files (x86)\Microsoft Visual Studio19\Professional\VC\Tools\MSVC.20.27508\bin\Hostx64\x64

回答by Anton Malyshev

Try to use "Visual Studio Command Prompt" (vcvarsall.bat)

尝试使用“Visual Studio 命令提示符”(vcvarsall.bat)

回答by e_soroush

As others said you can either run cmake in "Visual Studio Command Prompt" form the path @Miles said or (better way) add the path of visual studio compiler to your path. Check this path:C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\binand find it in your computer, then add it in your PATH environment variable.

正如其他人所说,您可以按照@Miles 所说的路径在“Visual Studio 命令提示符”中运行 cmake,或者(更好的方法)将 Visual Studio 编译器的路径添加到您的路径中。检查此路径:C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin并在您的计算机中找到它,然后将其添加到您的 PATH 环境变量中。

回答by danielbathke

I ran into the same problem. I realized that cl does not come with Visual Studio 2015, but when I installed the 2013 express, it worked.

我遇到了同样的问题。我意识到 cl 不随 Visual Studio 2015 一起提供,但是当我安装 2013 express 时,它起作用了。

Use the "Visual Studio 2013" -> "Visual Studio Tools" -> "VS2013 x64 Cross Tools Command Prompt".

使用“Visual Studio 2013”​​->“Visual Studio 工具”->“VS2013 x64 交叉工具命令提示符”。