C++ Academy · Lesson

Using vcpkg and Conan for Dependencies

Pull external libraries with vcpkg and Conan and integrate them with CMake.

Lesson 3 of 414 steps

Using vcpkg and Conan for Dependencies is a free C++ Academy lesson on CoddyKit. This is lesson 3 of 4. Any 3 lessons of this learning path are free to read in full — after that, CoddyKit PRO unlocks every lesson, plus hands-on practice with a built-in code editor and a 24/7 AI tutor. It is part of the C++ Academy learning path, and your progress syncs across the web and the CoddyKit app. The C++ Academy course includes 4 lessons in total.

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 spdlog

Linking 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.cmake

Using 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=missing

conanfile.txt Example

List requires, generators, and options.

[requires]
fmt/10.1.1
spdlog/1.12.0

[generators]
CMakeDeps
CMakeToolchain

Integrating 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.cmake

FetchContent: 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.

Free to start

Learn C++ with an AI tutor — free

Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.

Courses
51
Lessons
203

Frequently Asked Questions

Is the “Using vcpkg and Conan for Dependencies” lesson free?

Yes — any 3 lessons of the C++ Academy learning path, including “Using vcpkg and Conan for Dependencies”, are free to read in full here on the web. After that, CoddyKit PRO unlocks every lesson, plus interactive practice with a built-in code editor and a 24/7 AI tutor. The C++ Academy course includes 4 lessons in total.

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, so you can start here or from the beginning and move at your own pace. This is lesson 3 of 4.

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

  1. CMake Project Layout and CMakeLists.txt
  2. Targets Linking and Visibility PUBLIC PRIVATE
  3. Using vcpkg and Conan for Dependencies
  4. Generating IDE Files and Cross-Platform Builds
← Back to C++ Academy