Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/MicrosoftDocs/cpp-docs/llms.txt

Use this file to discover all available pages before exploring further.

Visual Studio supports multiple ways to organize, compile, and link C++ code — from fully integrated MSBuild projects to open-folder CMake workspaces and raw command-line toolchain invocations. Regardless of which system you choose, the underlying MSVC toolchain (cl.exe, link.exe, and the standard libraries) does the heavy lifting of turning source files into executables, DLLs, and static libraries. Building a C++ program involves three fundamental steps: the preprocessor expands #include directives and macros to produce translation units; the compiler (cl.exe) compiles each translation unit into COFF object files (.obj); and the linker (link.exe) merges object files and resolves external references to produce the final output. A build system wraps this pipeline with configuration files that describe which files to compile, which options to use, and how targets depend on each other.

The MSVC Build Toolchain

The Microsoft C++ (MSVC) Build Tools ship as part of the Desktop development with C++ workload in the Visual Studio Installer, and are also available as a free standalone download from the Build Tools for Visual Studio page. The standalone package lets you run the full MSVC toolchain on build servers without installing the IDE. The simplest possible build is a single cl.exe invocation:
cl /EHsc hello.cpp
This compiles hello.cpp, automatically invokes the preprocessor, and calls the linker to produce hello.exe. For anything larger than a trivial program, you will want one of the build systems described below.

Choosing a Build System

MSBuild / Visual Studio Projects

.vcxproj projects managed by the Visual Studio IDE. Best for Windows-only applications and teams that want the full IDE experience including property pages, wizards, and deep debugger integration.

CMake

Cross-platform build description in CMakeLists.txt files. Recommended for new projects, open-source libraries, and any code that also builds on Linux or macOS. First-class support in Visual Studio 2019 and later.

Command Line

Drive cl.exe, link.exe, MSBuild.exe, or nmake directly from the Developer Command Prompt. Useful for build servers, CI pipelines, and fine-grained control over the toolchain.

C++ Compilation Pipeline

1

Preprocessing

cl.exe runs the preprocessor on each source file, expanding #include directives, resolving macros, and producing translation units.
2

Compilation

Each translation unit is compiled into a COFF object file (.obj). Compiler options control optimization level, language standard, warning level, and debug information format.
3

Linking

link.exe combines object files and static libraries (.lib), resolves external symbol references, and produces an executable (.exe), DLL, or static library. Linker options control output file names, subsystem, import libraries, and link-time optimizations.

Build System Comparison

FeatureMSBuild (.vcxproj)CMakeCommand Line
IDE integrationNativeFull (VS 2019+)None
Cross-platformNoYesPartial
Configuration file.vcxproj / .propsCMakeLists.txt / CMakePresets.jsonScripts / makefiles
Incremental buildsYesYes (Ninja / MSBuild generator)Manual
vcpkg supportYesYesManual
CI / build serverMSBuild.execmake --buildDirect tool invocation

Project Types

Visual Studio ships several C++ project templates. The most common are:
  • Console Application — simple .exe with a main() entry point
  • Windows Desktop Application.exe with a WinMain() entry point and the Windows subsystem
  • Dynamic-Link Library (DLL) — shared library with exported functions
  • Static Library.lib archive linked into callers at build time
  • CMake Project — open-folder workflow, no .vcxproj generated
For cross-platform projects or projects that consume open-source libraries via vcpkg, CMake is the recommended approach. MSBuild .vcxproj projects are best suited for Windows-only applications that benefit from the full Visual Studio IDE integration.

Compiler and Linker Options

Both MSBuild and CMake ultimately invoke cl.exe and link.exe. Understanding the key options for each tool helps you make informed decisions regardless of which build system you use.

Compiler Options

Language standard (/std), optimization (/O1, /O2), debug info (/Zi), warning levels (/W4), runtime library (/MD, /MT), and more.

Linker Options

Output file (/OUT), PDB generation (/PDB), subsystem (/SUBSYSTEM), link-time code generation (/LTCG), and DLL exports (/DLL, /EXPORT).

Optimizations

Whole-program optimization (/GL), link-time code generation (/LTCG), Profile-Guided Optimization (PGO), and architecture-specific tuning (/favor).

Build docs developers (and LLMs) love