Practical guide Visual Studio C++
Use vcpkg libraries in Visual Studio
vcpkg downloads and builds C++ libraries, and its MSBuild integration adds their include directories, libraries, and DLLs to your project. In manifest mode, the libraries are listed in a vcpkg.json file next to the project.
Visual Studio property-page paths describe MSBuild projects. For CMake, configure the corresponding target or preset. Menu names can vary by Visual Studio version; use the cited reference for your toolset.
- vcpkg.jsonDeclare dependencies
- TripletChoose architecture + runtime
- MSBuildRestore, compile, and link
The manifest names the libraries; the triplet selects their architecture and runtime; MSBuild integrates the resulting files.
Install and integrate vcpkg
vcpkg is a component of the Desktop development with C++ workload in Visual Studio 2022 17.6 and
later, available in the Developer PowerShell. You can also clone it from GitHub and run bootstrap-vcpkg.bat.
Then run vcpkg integrate install once, so that MSBuild projects can use it.
Add a library
- In the Developer PowerShell, in the project folder, run
vcpkg new --application. It createsvcpkg.jsonandvcpkg-configuration.json. - Add the libraries:
vcpkg add port fmt. - In the project properties, set vcpkg > Use Vcpkg Manifest to Yes.
- Build: vcpkg builds the libraries the first time, then Visual Studio finds their headers and links them.
vcpkg.json — declare the library
{ "dependencies": [ "fmt" ]}main.cpp — use it
#include <fmt/core.h>int main() { fmt::print("Hello from C++\n");}Choose the triplet
The triplet decides how the libraries are built. It must match the runtime library of your project, or the link fails with LNK2038 or LNK4098:
x64-windows: DLLs, with the dynamic runtime (/MD), the default. vcpkg copies the DLLs next to your program.x64-windows-static: static libraries with the static runtime (/MT).x64-windows-static-md: static libraries with the dynamic runtime (/MD).
Set it in vcpkg > Triplet, or with Use Static Libraries, for each platform.
| Triplet | Library linkage | Release runtime |
|---|---|---|
x64-windows | Dynamic | /MD |
x64-windows-static | Static | /MT |
x64-windows-static-md | Static | /MD |
Debug builds use the corresponding /MDd or /MTd runtime. Match architecture and configuration as well.
Fix the usual errors
- C1083 cannot open include file: the manifest is not enabled for this
configuration, or the library is not in
vcpkg.json. - LNK2019: the library is installed for another platform or triplet, or the project was not integrated. Check the vcpkg section of the Build output.
- LNK2038 on
RuntimeLibrary: the triplet does not match Runtime Library.
Sources and scope
Official references
These links document the compiler, build system, or debugger behavior discussed here. Use the version selector on Microsoft Learn for your toolset. Example blocks are focused excerpts; required headers and build settings are stated alongside them.
Using CppPilot in Visual Studio
CppPilot connects your own Codex or Claude account to Visual Studio. If you have neither, CppPilot Cloud provides AI access for build fixes, reviews, crash analysis, and project checks. AI chat requires your own Codex or Claude account.