In vcpkg, how do VCPKG_LIBRARY_LINKAGE and VCPKG_CRT_LINKAGE differ, and which triplet ships a Windows tool without dependency DLLs or a separate MSVC runtime?
answer
- library kind versus runtime library
- /MD versus /MT
- static plus static-md variants
- your own code must match
basics
~20 sVCPKG_LIBRARY_LINKAGE chooses static libraries or DLLs for each port; VCPKG_CRT_LINKAGE chooses whether the MSVC runtime is linked statically (/MT) or as a DLL (/MD). x64-windows-static sets both to static, so the tool needs neither dependency DLLs nor the runtime installed.
solid answer
~40 sThe two triplet variables answer different questions. `VCPKG_LIBRARY_LINKAGE` decides whether each port is built as a static library or a DLL. `VCPKG_CRT_LINKAGE`, meaningful for MSVC, decides how those binaries link the C runtime: `dynamic` means `/MD` and the runtime DLLs, `static` means `/MT` and a copy inside each binary. The built-in `x64-windows` is dynamic for both; `x64-windows-static-md` builds static libraries on the dynamic CRT, which the vcpkg docs recommend when you redistribute the runtime; `x64-windows-static` is static for both, giving a single self-contained executable. Your own targets must use the same runtime, in CMake through the `MSVC_RUNTIME_LIBRARY` property (for example `MultiThreaded$<$<CONFIG:Debug>:Debug>`), or the MSVC linker reports a runtime library mismatch. Linkage is a preference: a port can force static with `vcpkg_check_linkage(ONLY_STATIC_LIBRARY)`.
code
cmake · 11 lines# triplets/x64-windows-static.cmake in the vcpkg registry (2026.10.16)
set(VCPKG_TARGET_ARCHITECTURE x64)
set(VCPKG_CRT_LINKAGE static)
set(VCPKG_LIBRARY_LINKAGE static)
set(VCPKG_PROVIDED_FORTRAN ON)
# triplets/x64-windows-static-md.cmake
set(VCPKG_TARGET_ARCHITECTURE x64)
set(VCPKG_CRT_LINKAGE dynamic)
set(VCPKG_LIBRARY_LINKAGE static)
set(VCPKG_PROVIDED_FORTRAN ON)go deeper
Recall that static and dynamic linkage exist for both the libraries and the MSVC runtime, and name x64-windows-static for a self-contained tool.
Explain the three Windows triplets, the /MD versus /MT mapping and how CMAKE_MSVC_RUNTIME_LIBRARY keeps your own code consistent.
Show you can diagnose a runtime library mismatch at link time, and handle ports that force a linkage through vcpkg_check_linkage.
Weigh a fully static distribution against servicing: static binaries are simple to ship, but every runtime or dependency fix means a rebuild and redeploy.
## Two different linkage decisions A vcpkg triplet carries two linkage settings that are easy to conflate: - `VCPKG_LIBRARY_LINKAGE` (`static` or `dynamic`) decides what **kind of library each port produces**: a static `.lib`/`.a` that is copied into your executable at link time, or a DLL/shared library loaded at run time. - `VCPKG_CRT_LINKAGE` (`static` or `dynamic`) decides how those binaries link the **C and C++ runtime**. The vcpkg docs describe it as the CRT linkage "for MSVC": with MSVC, `dynamic` corresponds to `/MD` (`/MDd` in debug), which links against the runtime DLLs, and `static` to `/MT` (`/MTd`), which copies the runtime into each binary. On Linux and macOS the built-in triplets set the CRT to `dynamic` and the variable has no comparable role, because the system C library is shared. ## The Windows triplets side by side | Triplet | `VCPKG_LIBRARY_LINKAGE` | `VCPKG_CRT_LINKAGE` | What you ship | |---|---|---|---| | `x64-windows` | dynamic | dynamic | exe + dependency DLLs + MSVC runtime | | `x64-windows-static-md` | static | dynamic | exe + MSVC runtime | | `x64-windows-static` | static | static | exe only | All three are in the top-level `triplets` directory of the 2026.10.16 registry, with the same split for `arm64-windows` and `arm64-windows-static-md`. The vcpkg Windows platform notes call the `static-md` triplets the recommended solution for redistributing the MSVC runtime, while `static` suits a single-file command-line tool copied onto machines you do not control. ## Making your own code match The CRT choice must be the same across every object file linked into one binary. With CMake, the runtime is set by the `MSVC_RUNTIME_LIBRARY` target property, initialised from `CMAKE_MSVC_RUNTIME_LIBRARY`; the property takes effect when policy `CMP0091` is `NEW`, which `cmake_minimum_required(VERSION 3.15)` or later gives you. Its default, `MultiThreaded$<$<CONFIG:Debug>:Debug>DLL`, matches the dynamic CRT. For `x64-windows-static` you set: ```cmake set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>") ``` before creating the targets, and select the triplet itself through the integration (covered with the CMake integration). If your code is `/MD` and the vcpkg libraries are `/MT`, or the reverse, the MSVC linker stops with a runtime library mismatch between object files. ## Linkage is a preference, not a guarantee The vcpkg docs say libraries "can ignore this setting if they do not support the preferred linkage type". Portfiles enforce their limits with `vcpkg_check_linkage`: - `ONLY_STATIC_LIBRARY` turns a `dynamic` request into a static build with a status note; the `catch2` port does this on Windows; - `ONLY_DYNAMIC_LIBRARY` switches a static request to a DLL, but if the triplet also sets a static CRT the port **fails** instead, because a DLL with its own static CRT "creates conditions many developers find surprising"; - `ONLY_DYNAMIC_CRT` and `ONLY_STATIC_CRT` fail outright when the triplet's CRT does not match. So a statically linked tool can still fail to build if one dependency only supports DLLs; the fix is a different library, a different triplet, or a per-port setting in a custom triplet. ## Checklist for a statically linked Windows tool 1. Select `x64-windows-static` as the target triplet. 2. Set `CMAKE_MSVC_RUNTIME_LIBRARY` to the non-DLL runtime for your own targets. 3. Build Release and Debug separately; vcpkg builds both configurations unless the triplet sets `VCPKG_BUILD_TYPE release`. 4. Inspect the executable's imported DLLs with a dependency viewer and confirm that only operating-system DLLs remain. 5. Expect larger binaries, and remember a security fix in a dependency or the runtime now requires rebuilding and reshipping the tool. ## Diagnosing a linkage surprise Most linkage questions about a vcpkg build reduce to three checks: - **Which triplet built the package?** The installed tree has one directory per triplet, and the install output names each package with its triplet, as in `zlib:x64-windows-static`. Libraries from `x64-windows` sitting where `x64-windows-static` was expected mean the triplet was never selected. - **Did the port honour the request?** The build log shows the note printed by `vcpkg_check_linkage` when a port switched linkage; a `bin` directory with DLLs under a static triplet usually traces back to one. - **Does your own code match?** Compare the runtime flags of your targets with the triplet's CRT setting; with CMake, read the `MSVC_RUNTIME_LIBRARY` value your targets end up with and confirm policy `CMP0091` is `NEW`. Because the triplet's text enters every package's ABI hash, switching between `x64-windows-static` and `x64-windows-static-md` never reuses binaries across the two; each is a separate set of cached packages.
- When would you choose x64-windows-static-md over x64-windows-static?When the product already installs the MSVC runtime, for example through its installer or the redistributable package. Static libraries still give one executable without dependency DLLs, while the shared runtime can be updated without rebuilding the tool; the vcpkg platform notes recommend the static-md triplets for redistributing the runtime.
- A port only supports DLLs. What happens with x64-windows-static?If its portfile calls `vcpkg_check_linkage(ONLY_DYNAMIC_LIBRARY)`, the build fails rather than producing a DLL with its own static CRT. Options are a custom triplet that builds that one port dynamically on a dynamic CRT, a different library, or the static-md triplet.
- VCPKG_CRT_LINKAGE static means the dependencies are built as static libraries.
- x64-windows-static-md links the MSVC runtime statically.
- A static triplet guarantees every port is built as a static library.
- Your own targets can keep /MD while linking x64-windows-static libraries.
- Linux triplets need VCPKG_CRT_LINKAGE static to produce static archives.