Compartir a través de


Setting the Path and Environment Variables for Command-Line Builds

The Visual C++ command-line build tools require several environment variables that are customized for your installation. When Visual Studio is installed, it creates command files that set the required environment variables, and then creates shortcuts that start a Command Prompt window that already has these variables set. 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 the vcvarsall.bat command file.

The Visual C++ command-line tools use the PATH, TMP, INCLUDE, LIB, and LIBPATH environment variables, and may also use tool-specific environment variables. Because the values of these environment variables are specific to your installation, and can be changed by product updates or upgrades, we recommend that you use vcvarsall.bat or a Developer Command Prompt shortcut instead of setting them yourself. For information about the specific environment variables used by the compiler and linker, see CL Environment Variables and LINK Environment Variables.

Note

Several command-line tools or tool options require Administrator permission. To use them, we recommend that you open a Command Prompt window by using the Run as Administrator option (on the shortcut menu for the Command Prompt window you want to open).

Using the Command Prompt shortcuts

The Developer Command Prompt shortcut that's included in every edition of Visual Studio opens a Command Prompt window and sets the environment to use the 32-bit x86-native toolset to target x86 processors. Command Prompts for 32-bit cross-compilers that target x64 and ARM platforms are also available. Depending on your system and the edition of Visual Studio installed, a Command Prompt shortcut for a 64-bit x64-native toolset that targets x64 processors, and one for a 64-bit cross-compiler that targets x86 processors, may also be available. These versions of the command-line toolset are available in all editions of Visual Studio:

  • x86 on x86
    Use this toolset to create output files for x86 machines. It runs as a 32-bit process, native on an x86 machine and under WOW64 on a 64-bit Windows operating system.

  • x64 on x86 (x64 cross-compiler)
    Use this toolset to create output files for x64. It runs as a 32-bit process, native on an x86 machine and under WOW64 on a 64-bit Windows operating system.

  • ARM on x86 (ARM cross compiler)
    Use this toolset to create output files for ARM machines. It runs as a 32-bit process, native on an x86 machine and under WOW64 on a 64-bit Windows operating system.

These versions of the command-line toolset are available on 64-bit platforms:

  • x86 on x64
    Use this toolset to create output files for x86 machines. It runs as a native process on a 64-bit Windows operating system.

  • x64 on x64
    Use this toolset to create output files for x64 machines. It runs as a native process on a 64-bit Windows operating system.

  • ARM on x64 (ARM cross compiler)
    Use this toolset to create output files for ARM machines. It runs as a native 64-bit process on a 64-bit Windows operating system.

To open a Developer Command Prompt window

  1. With the Windows 8 Start screen showing, type Visual Studio Tools. Notice that the search results change as you type; when Visual Studio Tools appears, choose it.

    On earlier versions of Windows, choose Start, and then in the search box, type Visual Studio Tools. When Visual Studio Tools appears in the search results, choose it.

  2. In the Visual Studio Tools folder, open the Developer Command Prompt for your version of Visual Studio. (To run as administrator, open the shortcut menu for the Developer Command Prompt and choose Run as Administrator.)

The Developer Command Prompt sets the environment to use the 32-bit native toolset to target x86 processors. Choose the x64 Cross Tools Command Prompt to use the 32-bit native toolset to target x64 processors. Choose the ARM Cross Tools Command Prompt to use the 32-bit native toolset to target ARM processors. Choose the x64 Native Tools Command Prompt to use the 64-bit native toolset to target x64 processors.

Using vcvarsall.bat in a Command Prompt window

By running vcvarsall.bat in a plain Command Prompt window, you can set environment variables to configure the command line for native 32-bit or 64-bit compilation, or for cross-compilation to x86, x64, or ARM processors. If no arguments are provided, vcvarsall.bat configures the environment variables for using the 32-bit native compiler for x86 targets. However, you can use it to configure any of the compilers. If you specify a compiler configuration that is not installed or is not available on your build computer architecture, a message is displayed. The following table shows the supported arguments.

Vcvarsall.bat argument

Compiler

Build-computer architecture

Build output architecture

x86

x86 32-bit native

x86, x64

x86

x86_amd64

x64 on x86 cross

x86, x64

x64

x86_arm

ARM on x86 cross

x86, x64

ARM

amd64

x64 64-bit native

x64

x64

amd64_x86

x86 on x64 cross

x64

x86

amd64_arm

ARM on x64 cross

x64

ARM

The following steps show how to configure a Command Prompt to use the 32-bit native toolset to target x86 platforms.

To run vcvarsall.bat

  1. At the command prompt, change to the Visual C++ installation directory. (The location depends on the system and the Visual Studio installation, but a typical location is C:\Program Files (x86)\Microsoft Visual Studio version\VC\.) For example, enter:

    cd "\Program Files (x86)\Microsoft Visual Studio 12.0\VC"

  2. To configure this Command Prompt window for 32-bit x86 command-line builds, at the command prompt, enter:

    vcvarsall x86

Visual Studio also provides vcvars32.bat to set up a command-line environment. The vcvars32.bat file is limited to setting the appropriate environment variables to enable 32-bit x86 command-line builds. It's the equivalent of the vcvarsall x86 command.

If you are using DEVENV for command-line builds, the environment set by vcvarsall.bat or vcvars32.bat does not affect your builds, unless you also specify the /useenv option.

Warning

The vcvarsall.bat file can vary from computer to computer. Do not replace a missing or damaged vcvarsall.bat file by using a file from another computer. Rerun Visual Studio Setup to replace the missing file.

The vcvarsall.bat file also varies from version to version. If the current version of Visual C++ is installed on a computer that also has an earlier version of Visual C++, do not run vcvarsall.bat or vcvars32.bat from the different versions in the same Command Prompt window.

See Also

Reference

Linker Options

Compiler Options

Concepts

Linking

Other Resources

Building on the Command Line

Compiling a C/C++ Program