vcpkg
Manage C and C++ libraries
TLDR
Build and add package libcurl to the vcpkg environment
Build and add zlib using the emscripten toolchain
Search for a package
Configure a CMake project to use vcpkg packages
SYNOPSIS
vcpkg [options] <command> [arguments]
PARAMETERS
install <package>...
Installs one or more specified packages and their dependencies for a given triplet (e.g., x64-linux).
search [pattern]
Searches for available packages in the vcpkg registry. A pattern can be provided to filter results by name.
list
Lists all currently installed packages, along with their versions and triplet information.
remove <package>...
Removes one or more specified installed packages. This also removes any packages that solely depended on the removed ones.
update
Updates the vcpkg tool itself and checks for available updates to installed packages. It can also update installed ports.
integrate install
Integrates vcpkg with your development environment, primarily CMake and MSBuild, to simplify finding installed libraries by projects.
build <package> [options]
Builds a specific package from source without necessarily installing it into the default location. Useful for debugging build issues.
export <package>... [options]
Exports specified installed packages into a distributable format such as a NuGet package, a zip file, or a 7zip archive.
owns <file>
Determines which installed vcpkg package owns a given file path by searching through installed package files.
env [options]
Launches a shell with vcpkg's environment variables set, which can be useful for manual compilation or debugging within the vcpkg environment.
help [command]
Displays help information for the vcpkg tool itself or detailed help for a specific subcommand.
DESCRIPTION
vcpkg is a free and open-source C/C++ package manager developed by Microsoft. Its primary purpose is to simplify the acquisition and management of C and C++ libraries for various development environments, including Visual Studio, Visual Studio Code, and CMake projects. It supports multiple platforms like Windows, Linux, and macOS. vcpkg builds libraries from source, which offers greater flexibility in terms of compiler versions and configurations, but can also lead to longer installation times. It integrates well with CMake via toolchain files, allowing projects to easily find and link against installed libraries. It also handles transitive dependencies automatically, making dependency management easier for complex C++ projects.
CAVEATS
Slow Installation: vcpkg builds libraries from source, which can lead to significantly longer installation times compared to binary package managers, especially for large projects or on slower machines.
Disk Space Usage: Due to source-based builds and the caching of build artifacts, vcpkg can consume a substantial amount of disk space.
Compiler Dependency: Requires a compatible C/C++ compiler toolchain (e.g., GCC, Clang on Linux) to be pre-installed and properly configured on the system.
C++ Specific: It is primarily designed for managing C/C++ libraries and is not a general-purpose system package manager like apt or dnf.
TRIPLETS
vcpkg uses the concept of triplets to define a specific target platform, architecture, and configuration (e.g., x64-linux for 64-bit Linux, or x86-windows-static for 32-bit Windows with static linking). Packages are installed for specific triplets, allowing multiple configurations of the same library to coexist and be managed independently.
MANIFEST FILES (VCPKG.JSON)
For per-project dependency management, vcpkg supports manifest files (vcpkg.json). This file defines the project's direct and transitive dependencies and features, enabling vcpkg to automatically install necessary libraries when configured with CMake or other build systems, promoting reproducible builds.
TOOLCHAIN INTEGRATION
vcpkg integrates seamlessly with CMake via a toolchain file (vcpkg.cmake). By passing -DCMAKE_TOOLCHAIN_FILE=<path_to_vcpkg>/scripts/buildsystems/vcpkg.cmake
to CMake, projects can automatically find and link against libraries installed by vcpkg, simplifying the build process significantly.
HISTORY
vcpkg was initially developed by Microsoft in 2016 to address the inherent challenges of managing C++ libraries on Windows, particularly within the Visual Studio ecosystem. Its early focus was on providing a consistent and reliable way to acquire and link third-party dependencies. Over time, its scope expanded significantly to become a robust cross-platform solution, supporting Linux and macOS, and integrating seamlessly with CMake-based build systems. Its design philosophy emphasizes building libraries from source, which offers maximum flexibility and control over compiler versions and configurations, contributing to its growing adoption within the C++ development community for complex dependency management.