为命令行生成设置路径和环境变量Set the Path and Environment Variables for Command-Line Builds

Microsoft C++ (MSVC) 命令行生成工具需要多个为安装和生成配置自定义的环境变量。The Microsoft C++ (MSVC) command-line build tools require several environment variables that are customized for your installation and build configuration. 当通过 Visual Studio 安装程序安装 C++ 工作负载时,它会创建用于设置所需环境变量的自定义命令文件或批处理文件。When a C++ workload is installed by the Visual Studio installer, it creates customized command files, or batch files, that set the required environment variables. 安装程序随后使用这些命令文件为 Windows“开始”菜单创建快捷方式,用于打开开发人员命令提示窗口。The installer then uses these command files to create shortcuts for the Windows Start menu to open a developer command prompt window. 这些快捷方式为特定生成配置设置环境变量。These shortcuts set up the environment variables for a specific build configuration. 当你要使用命令行工具时,可以运行这些快捷方式之一,也可以打开纯命令提示窗口,然后运行自定义命令文件之一来自己设置生成配置环境。When you want to use the command-line tools, you can run one of these shortcuts, or you can open a plain command prompt window and then run one of the custom command files to set the build configuration environment yourself. 有关详细信息,请参阅通过命令行使用 MSVC 工具集For more information, see Use the MSVC toolset from the command line. 若要通过纯命令提示符使用命令文件,请参阅标题为开发人员命令文件位置一节。To use the command files with a plain command prompt, see the section entitled Developer command file locations.

MSVC 命令行工具使用 PATH、TMP、INCLUDE、LIB 和 LIBPATH 环境变量,还使用特定于已安装工具、平台和 SDK 的其他环境变量。The MSVC command-line tools use the PATH, TMP, INCLUDE, LIB, and LIBPATH environment variables, and also use other environment variables specific to your installed tools, platforms, and SDKs. 即使是简单 Visual Studio 安装,也可以设置二十或更多个环境变量。Even a simple Visual Studio installation may set twenty or more environment variables. 由于这些环境变量的值特定于安装和生成配置选择,并且可能因产品更新或升级而进行更改,因此强烈建议使用开发人员命令提示快捷方式或自定义命令文件之一来设置它们,而不是自己在 Windows 环境中设置它们。Because the values of these environment variables are specific to your installation and your choice of build configuration, and can be changed by product updates or upgrades, we strongly recommend that you use a developer command prompt shortcut or one of the customized command files to set them, instead of setting them in the Windows environment yourself.

若要查看通过开发人员命令提示快捷方式设置的环境变量,可以使用 SET 命令。To see which environment variables are set by a developer command prompt shortcut, you can use the SET command. 打开纯命令提示窗口,并捕获 SET 命令输出以用作基线。Open a plain command prompt window and capture the output of the SET command for a baseline. 打开开发人员命令提示窗口,并捕获 SET 命令输出以用于比较。Open a developer command prompt window and capture the output of the SET command for comparison. 差异工具(如 Visual Studio IDE 中内置的工具)可用于比较环境变量并查看通过开发人员命令提示设置的内容。A diff tool such as the one built into the Visual Studio IDE can be useful to compare the environment variables and see what is set by the developer command prompt. 有关由编译器和链接器使用的特定环境变量的信息,请参阅 CL 环境变量For information about the specific environment variables used by the compiler and linker, see CL Environment Variables.

备注

多个命令行工具或工具选项可能需要管理员权限。Several command-line tools or tool options may require Administrator permission. 如果在使用它们时遇到权限问题,则建议使用“以管理员身份运行”选项打开开发人员命令提示窗口 。If you have permission issues when you use them, we recommend that you open the developer command prompt window by using the Run as Administrator option. 在 Windows 10 上,右键单击以打开命令提示窗口的快捷菜单,然后依次选择“更多” 、“以管理员身份运行” 。On Windows 10, right-click to open the shortcut menu for the command prompt window, then choose More, Run as administrator.

请参阅See also

通过命令行使用 MSVC 工具集Use the MSVC toolset from the command line
MSVC 链接器参考MSVC linker reference
MSVC 链接器选项MSVC Linker Options
MSVC 编译器参考MSVC Compiler Reference
MSVC 编译器选项MSVC Compiler Options