Building on the Command Line

You can build C and C++ applications on the command line by using tools that are included in Visual Studio. Every edition of Visual Studio installs a command-line toolset that includes a compiler, linker, and other build tools, and a command file that sets the required build environment. By default, these tools are installed in drive:\Program Files (x86)\Microsoft Visual Studio version\VC\bin\. (The actual directory on your computer depends on the system, the Visual Studio version, and your installation choices.)

To work correctly, the Visual C++ command-line tools require several environment variables that are customized for your installation. When Visual Studio is installed, it creates a vcvarsall.bat command file that you can run to set the required environment variables. It also creates a shortcut that starts a Developer Command Prompt window in which these variables are already set. These environment variables are specific to your installation, and might be changed by product updates or upgrades. Therefore, we recommend that you use vcvarsall.bat or a Developer Command Prompt shortcut instead of setting them yourself. For more information, see Setting the Path and Environment Variables for Command-Line Builds.

To open a Developer Command Prompt window

  1. On the Windows 8 Start screen, enter 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, enter 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 build a C/C++ project on the command line, you can use these Visual C++ command-line tools:

  • CL
    Use the compiler (cl.exe) to compile and link source code files into apps, libraries, and DLLs.

  • Link
    Use the linker (link.exe) to link compiled object files and libraries into apps and DLLs.

  • MSBuild (Visual C++)
    Use MSBuild (msbuild.exe) to build Visual C++ projects and Visual Studio solutions. This is equivalent to running the Build project or Build Solution command in the Visual Studio IDE.

  • DEVENV
    Use DEVENV (devenv.exe) combined with a command-line switch—for example, /Build or /Clean—to perform certain build commands without displaying the Visual Studio IDE.

  • NMAKE
    Use NMAKE (nmake.exe) to automate tasks that build Visual C++ projects by using a traditional makefile.

When you build on the command line, you can get information about warnings, errors, and messages by starting Visual Studio and then on the menu bar, choosing Help, Search.

In This Section

The articles in this section of the documentation show how to build apps on the command line, describe how to customize the command-line build environment to use 64-bit toolsets and target x86, x64, and ARM platforms, and demonstrate how to use the command-line build tools MSBuild and NMAKE.

See Also

Other Resources

Building C/C++ Programs