共用方式為


Building on the Command Line

 

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at 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 Start menu, open All apps and then open the Visual Studio folder for your version of Visual Studio. In some versions of Visual Studio, the folder is called Visual Studio Tools.

  2. In the Visual Studio folder, choose the Developer Command Prompt for your version of Visual Studio. If you've installed the Visual C++ Build Tools edition, choose the x86 Native Tools Command Prompt.

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.

Walkthrough: Compiling a Native C++ Program on the Command Line
Gives an example that shows how to create and compile a simple C++ program on the command line.

Walkthrough: Compiling a C Program on the Command Line
Describes how to compile a program written in the C programming language.

Walkthrough: Compiling a C++/CLI Program on the Command Line
Describes how to create and compile a C++/CLI program that uses the .NET Framework.

Walkthrough: Compiling a C++/CX Program on the Command Line
Describes how to create and compile a C++/CX program that uses the Windows Runtime.

Setting the Path and Environment Variables for Command-Line Builds
Describes how to start a Command Prompt window that has the required environment variables set for command-line builds that target x86, x64, and ARM platforms by using a 32-bit or 64-bit toolset.

NMAKE Reference
Provides links to articles that describe the Microsoft Program Maintenance Utility (NMAKE.EXE).

MSBuild (Visual C++)
Provides links to articles that discuss how to use MSBuild.EXE.

/MD, /MT, /LD (Use Run-Time Library)
Describes how to use these compiler options to use a Debug or Release run-time library.

C/C++ Compiler Options
Provides links to articles that discuss the C and C++ compiler options and CL.exe.

Linker Options
Provides links to articles that discuss the linker options and LINK.exe.

C/C++ Build Tools
Provides links to the C/C++ build tools that are included in Visual Studio.

See Also

Building C/C++ Programs