C++ Package Management: Escape Dependency Hell with vcpkg & Conan [#40-1]

C++ Package Management: Escape Dependency Hell with vcpkg & Conan [#40-1]

이 글의 핵심

Declarative C++ dependencies with vcpkg.json or Conan—reproducible builds for teams and CI.

Introduction: “How do I add this library?”

Manual downloads and include paths diverge per machine. vcpkg (Microsoft, CMake-first) and Conan (cross-platform, rich profiles) turn dependencies into declared, reproducible builds.

Covers: vcpkg.json manifest, triplets, overlays; conanfile.txt/py, profiles, lockfiles; CMake integration; CI; error catalog; best practices.


Table of contents

  1. Dependency hell scenarios
  2. vcpkg
  3. Conan
  4. Comparison
  5. Common errors
  6. Best practices
  7. Production patterns
  8. Summary

1. Scenarios

Different paths per dev, Windows vs Linux drift, spdlog version skew, find_package failures—manifests + toolchains fix this.

flowchart LR
  subgraph before["Manual"]
    A1[Dev A path] --- X[Mismatch]
    B1[CI path] --- X
  end
  subgraph after["Manager"]
    M[vcpkg.json] --> U[Same graph everywhere]
  end

2. vcpkg

Bootstrap vcpkg, use manifest mode with vcpkg.json +:

set(CMAKE_TOOLCHAIN_FILE "${CMAKE_CURRENT_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake"
    CACHE STRING "")

Pin builtin-baseline for reproducibility. Choose triplets (x64-linux, x64-windows-static, …).


3. Conan 2

conan install . --output-folder=build --build=missing then:

cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=build/conan_toolchain.cmake

Use lockfiles (conan lock create) for CI reproducibility.


4. vcpkg vs Conan (summary)

vcpkgConan
CMaketoolchain one-linergenerated toolchain
Custom recipesoverlaysconanfile.py
EnterpriseportsArtifactory remotes

Pick one per repo unless you have a strong integration story.


5. Common errors

  • Could not find package configuration file → missing CMAKE_TOOLCHAIN_FILE or package not built.
  • Conan find_package fails → forgot conan_toolchain.cmake.
  • Version conflicts → adjust requires, use graph visualization.
  • C++ standard mismatch → target_compile_features(... cxx_std_17).

6. Best practices

Manifest/lock in Git, document triplets, cache CI artifacts, prefer find_package(... CONFIG).


7. Production patterns

GitHub Actions matrix with CMAKE_TOOLCHAIN_FILE, Docker base images, CMakePresets.json for shared dev configs.


8. Summary

  • vcpkg: manifest + toolchain for CMake-first teams.
  • Conan: profiles + lockfiles + remotes for heterogeneous compilers.

Next: CI/CD GitHub Actions (#40-2)
Previous: SIMD & execution (#39-3)

Keywords

vcpkg, Conan, CMake dependencies, reproducible build, C++ package manager