Using vcpkg and Conan for Dependencies
Pull external libraries with vcpkg and Conan and integrate them with CMake.
Using vcpkg and Conan for Dependencies is a free C++ Academy lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the C++ Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Why a Package Manager?
Manually downloading and building dependencies for C++ is painful. Package managers automate fetching, building, and configuring third-party libraries.
The Two Dominant Options
Two leading C++ package managers:
- vcpkg — Microsoft-backed, source-only, integrates with CMake
- Conan — open-source, supports binaries, more flexible
vcpkg Setup
Clone the vcpkg repository and bootstrap. Set the toolchain file in your CMake call.
git clone https://github.com/microsoft/vcpkg.git
cd vcpkg && ./bootstrap-vcpkg.sh
./vcpkg install fmt spdlogLinking with vcpkg in CMake
Pass the toolchain file when configuring CMake. find_package then works as usual.
cmake -B build -DCMAKE_TOOLCHAIN_FILE=$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmakeUsing vcpkg.json (Manifest Mode)
Declare dependencies in a vcpkg.json file. vcpkg installs them per project.
{
"name": "my-app",
"version-string": "0.1.0",
"dependencies": ["fmt", "spdlog", "nlohmann-json"]
}Conan Setup
Install Conan with pip; create a conanfile.txt or conanfile.py.
pip install conan
conan profile detect
conan install . --build=missingconanfile.txt Example
List requires, generators, and options.
[requires]
fmt/10.1.1
spdlog/1.12.0
[generators]
CMakeDeps
CMakeToolchainIntegrating Conan with CMake
Conan generates CMake files when you run install. Use them via the toolchain file or by including the generated CMake files.
cmake -B build -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmakeFetchContent: CMake-Native Alternative
For simple cases, CMake has built-in FetchContent to download and add dependencies at configure time.
include(FetchContent)
FetchContent_Declare(fmt
GIT_REPOSITORY https://github.com/fmtlib/fmt.git
GIT_TAG 10.1.1
)
FetchContent_MakeAvailable(fmt)
target_link_libraries(myapp PRIVATE fmt::fmt)Choosing a Tool
Quick guide:
- Small projects →
FetchContent - Larger projects, simple deps →
vcpkg - Complex builds, binary cache →
Conan
Reproducible Builds
Pin specific versions in your manifest. Lock files (conan.lock) capture exact resolved versions for reproducibility.
Caching Binaries
Both Conan and vcpkg support binary caching — CI builds become orders of magnitude faster. Set up a shared cache for your team.
Quick Check
Which CMake mechanism downloads and builds a dependency at configure time without requiring an external tool?
Recap
vcpkg and Conan automate C++ dependency management. CMake s FetchContent is a lightweight alternative. Pin versions, cache binaries, and use find_package in CMake to consume installed libraries.
Frequently asked questions
Is the “Using vcpkg and Conan for Dependencies” lesson free?
Yes — the full text of “Using vcpkg and Conan for Dependencies” is free to read here on the web, and the C++ Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the C++ Academy course, upgrade to CoddyKit PRO.
What will I learn in “Using vcpkg and Conan for Dependencies”?
Pull external libraries with vcpkg and Conan and integrate them with CMake. You practise C++ Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start C++ Academy?
No prior experience is required. C++ Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Using vcpkg and Conan for Dependencies” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this C++ Academy lesson?
Yes. Every C++ Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- CMake Project Layout and CMakeLists.txt
- Targets Linking and Visibility PUBLIC PRIVATE
- Using vcpkg and Conan for Dependencies
- Generating IDE Files and Cross-Platform Builds