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.

Microsoft C++ (MSVC) is not a single tool but a complete, integrated toolset for building native C and C++ applications on Windows. When developers refer to “MSVC,” they typically mean the combination of the cl.exe compiler, the link.exe linker, the C++ Standard Library, the C Runtime Library (CRT), the Visual Studio debugger, and a suite of companion utilities — all of which ship together as part of Visual Studio and the standalone Microsoft C++ Build Tools. Understanding each component and how they interlock is key to using the toolset effectively.

The MSVC Compiler: cl.exe

cl.exe is the Microsoft C and C++ compiler driver. It accepts .c and .cpp source files and produces COFF-format object files (.obj) that the linker can combine into executables or libraries. A single invocation of cl.exe can also invoke the linker automatically, making it easy to compile-and-link in one step.
cl.exe /W4 /O2 /std:c++20 /EHsc main.cpp
Key capabilities of cl.exe include:
  • C++ standards support/std:c++14, /std:c++17, /std:c++20, /std:c++latest select the language standard. MSVC tracks the ISO standard closely and publishes a conformance table for each release.
  • Optimization levels/Od (debug, no optimization), /O1 (minimize size), /O2 (maximize speed), /Ox (full optimization). Whole-program optimization (/GL) combined with link-time code generation (/LTCG) enables cross-module inlining.
  • Security mitigations/GS (buffer security checks), /guard:cf (control-flow guard), /Qspectre (Spectre mitigation), and /sdl (additional security development lifecycle checks).
  • Diagnostics/W0 through /W4 and /Wall control warning verbosity. /analyze enables static analysis. /diagnostics:caret shows the precise token that caused an error.
  • Precompiled headers/Yc creates a precompiled header; /Yu uses one. This dramatically reduces rebuild times in large projects.
link.exe combines object files and library files into a final output — an executable (.exe), a dynamic-link library (.dll), or a static library (.lib). It reads .obj files produced by cl.exe and resolves cross-file symbol references.
link.exe main.obj helper.obj /OUT:myapp.exe /SUBSYSTEM:CONSOLE
Notable linker features:
  • Incremental linking (/INCREMENTAL) — only re-links changed sections, dramatically speeding up edit-build-debug cycles.
  • Profile-guided optimization (/PGO) — uses profiling data collected from real workloads to reorganize code for better CPU cache utilization.
  • Control-flow guard (/guard:cf) — inserts runtime checks that prevent attackers from redirecting execution through function pointers.
  • COMDAT folding (/OPT:ICF) — merges identical functions and data to reduce binary size.
  • Delay-load imports (/DELAYLOAD) — defers loading of DLLs until the first call into them.

The C++ Standard Library

MSVC ships a complete implementation of the ISO C++ Standard Library. This includes all headers mandated by C++11 through C++23, such as <algorithm>, <vector>, <string>, <filesystem>, <ranges>, <format>, <coroutine>, and <print>. The Standard Library implementation is developed openly on GitHub (microsoft/STL) and is updated with every Visual Studio release.
#include <vector>
#include <algorithm>
#include <print>

int main() {
    std::vector<int> v = {5, 3, 1, 4, 2};
    std::ranges::sort(v);
    std::println("Sorted: {}", v[0]); // C++23 std::print
}
The Standard Library is a header-only interface backed by compiled static or import libraries (e.g., msvcprt.lib). You never need to manually link these; the compiler inserts the correct #pragma comment(lib, ...) directives automatically.

The C Runtime Library (CRT)

The Microsoft C Runtime Library provides the foundational C runtime functions: memory allocation (malloc/free), standard I/O (printf, fopen), string manipulation, math functions, and process initialization. Since Windows 10, the core CRT — the Universal CRT (UCRT) — ships as part of Windows itself (ucrtbase.dll). The Visual C++ CRT adds compiler-specific extensions on top. The CRT comes in several flavors selected by compiler switches:
SwitchRuntimeDescription
/MTlibcmt.libStatic CRT, release build
/MTdlibcmtd.libStatic CRT, debug build
/MDmsvcrt.libDynamic CRT, release build
/MDdmsvcrtd.libDynamic CRT, debug build
All modules in a single process must use the same CRT flavor. Mixing /MT and /MD across DLLs causes heap corruption and crashes at runtime.

The Debugger

The Visual Studio native debugger provides a first-class debugging experience for MSVC-compiled code. It integrates directly with the IDE and supports:
  • Breakpoints and conditional breakpoints — pause execution at any line or when a boolean expression becomes true.
  • Data breakpoints — break when the value at a memory address changes.
  • Watch, Autos, and Locals windows — inspect and modify variable values live while paused.
  • Call stack inspection — navigate up and down the call stack and examine local state at each frame.
  • Edit and Continue — modify source code while the process is running and apply changes without restarting (requires /ZI compile flag).
  • Just My Code — skip over framework and library code when stepping, focusing only on your own source.
  • Remote debugging — attach to a process running on a remote Windows machine or a Linux machine over SSH.

The Profiler

Visual Studio includes a performance profiler accessible from Debug > Performance Profiler. It provides several analysis tools:
Samples the call stack at regular intervals to show which functions consume the most CPU time. Useful for finding hot paths in computationally intensive code.
Takes heap snapshots and shows object allocations over time. Identifies memory leaks and excessive allocation pressure.
Inserts timing probes around every function call to produce exact elapsed-time measurements. Higher overhead than sampling but gives precise data.

Toolset Versions and Visual Studio Releases

MSVC toolset versions are identified by a v1xx number that maps to a Visual Studio release. The toolset version determines the compiler ABI, the Standard Library version, and which language features are available.
Visual Studio VersionToolset VersionCompiler Version (_MSC_VER)
Visual Studio 2015v1401900
Visual Studio 2017v1411910–1916
Visual Studio 2019v1421920–1929
Visual Studio 2022v1431930–1944+
You can install multiple toolsets side-by-side. For example, Visual Studio 2022 can build projects using the v141 (VS 2017) or v142 (VS 2019) toolset by selecting the appropriate Platform Toolset in the project’s property pages. This is essential for organizations that ship SDKs or libraries that must remain ABI-compatible with older compilers.
The predefined macro _MSC_VER exposes the compiler version at compile time. Use _MSVC_LANG to query the active C++ language standard version in your source code.

Standalone Build Tools

If you need the MSVC compiler without the full Visual Studio IDE, Microsoft provides the Microsoft C++ Build Tools as a separate download. This installs cl.exe, link.exe, the Standard Library, the Windows SDK, and MSBuild — everything needed to build C++ projects from the command line or in CI/CD pipelines — without installing the IDE. The Developer Command Prompt for VS (or vcvarsall.bat) sets up the environment variables (PATH, INCLUDE, LIB, LIBPATH) needed to use the build tools from any command prompt window.
"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat" x64
cl.exe /std:c++20 /EHsc hello.cpp

Build docs developers (and LLMs) love