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
- Dependency hell scenarios
- vcpkg
- Conan
- Comparison
- Common errors
- Best practices
- Production patterns
- 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)
| vcpkg | Conan | |
|---|---|---|
| CMake | toolchain one-liner | generated toolchain |
| Custom recipes | overlays | conanfile.py |
| Enterprise | ports | Artifactory remotes |
Pick one per repo unless you have a strong integration story.
5. Common errors
Could not find package configuration file→ missingCMAKE_TOOLCHAIN_FILEor package not built.- Conan
find_packagefails → forgotconan_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