Why C/C++ Needs Package Managers
Rust has Cargo, Go has modules, JavaScript has npm. C and C++ have no package manager in the language or the standard, and that gap has a long history: libraries copied into third_party/ folders, Git submodules nobody updates, apt install libfoo-dev on one machine and Homebrew on another, and build scripts that only work on the laptop of the person who wrote them. This course teaches the tools that close the gap: Conan 2, vcpkg and CPM.cmake.
Who this course is for
You can build a small C++ project with CMake: add_executable, target_link_libraries, find_package, build types and presets. If those are new, work through Modern CMake first; this course builds on it and doesn't repeat it. You don't need to know any package manager yet.
Why C++ is harder than other languages
A Python wheel or an npm package mostly contains source code or bytecode that runs anywhere. A C++ library ends up as machine code that has to match the program it links into:
| Must match | Why |
|---|---|
| Operating system and CPU architecture | a Linux x86-64 .a file can't link into a Windows ARM64 program |
| Compiler and its version | name mangling, standard library layout and inlined code differ |
| Standard library and its ABI | libstdc++ vs libc++, the old vs new std::string ABI on Linux |
| Build type | Debug and Release builds of MSVC's runtime are not interchangeable |
| Language standard | some libraries change their API or layout between C++17 and C++20 |
| Options | static or shared, header-only or compiled, optional features |
So a C++ package manager must do two jobs other ecosystems mostly don't: describe the configuration a binary was built for, and build from source when no matching binary exists. You'll meet this idea again and again: Conan calls it the package ID, vcpkg calls it the ABI hash and the triplet.
The options
| Approach | How it works | Main weakness |
|---|---|---|
| Vendoring | copy the library's source into your repository | updates are manual; patches get lost |
| Git submodules | point at another repository's commit | still built by your build system; no dependency graph |
| System packages | apt, dnf, brew, pacman |
one version per machine; differs between distros and OSes |
| CMake FetchContent | download and build the source during configure | rebuilds everything from source; no binaries, weak version handling |
| CPM.cmake | a thin layer over FetchContent with a source cache | same: source only, no binary reuse |
| vcpkg | Microsoft's port collection, pinned by a baseline, binary caching keyed by an ABI hash | one curated version per port per baseline (overrides aside) |
| Conan 2 | recipes + binary packages per configuration, remotes, lockfiles | the most concepts to learn |
The course spends most of its time on Conan (the most flexible, and the one the Build & Release track treats as mandatory), then vcpkg, then CPM, and ends with a comparison to help you choose.
A first look
Here is the whole idea in one session: a two-line conanfile.txt asks for fmt, conan install finds it and writes CMake files, and CMake builds against it without knowing where fmt lives.
mkdir -p hello && cd hello
cat > conanfile.txt <<'TXT'
[requires]
fmt/12.1.0
[generators]
CMakeDeps
CMakeToolchain
[layout]
cmake_layout
TXT
cat > CMakeLists.txt <<'TXT'
cmake_minimum_required(VERSION 3.25)
project(hello CXX)
find_package(fmt REQUIRED CONFIG)
add_executable(hello main.cpp)
target_link_libraries(hello PRIVATE fmt::fmt)
TXT
cat > main.cpp <<'SRC'
#include <fmt/core.h>
int main() { fmt::print("Hello from fmt {}!\n", FMT_VERSION); }
SRC
conan install . -c tools.build:jobs=1 > install.log 2>&1 && tail -1 install.log
cmake --preset conan-release > /dev/null
cmake --build --preset conan-release
./build/Release/helloInstall finished successfully
[ 50%] Building CXX object CMakeFiles/hello.dir/main.cpp.o
[100%] Linking CXX executable hello
[100%] Built target hello
Hello from fmt 120100!
The next lessons take this apart line by line.
How the sessions in this course run
Every bash session in this course is a real terminal session, recorded in a Linux container (Ubuntu 24.04, GCC 13, CMake 4.4, Conan 2.33, vcpkg 2026.10.16, CPM.cmake 0.43.2) without network access. The container comes with a few packages already built:
| Tool | Available offline |
|---|---|
| Conan | fmt/12.1.0, spdlog/1.17.0, catch2/3.16.0, for the default profile (gcc 13, gnu17, Release) |
| vcpkg | fmt 12.2.0, spdlog 1.17.0, catch2 3.16.0 for the x64-linux triplet, from a binary cache; a full clone (all version history) with the sources of fmt 12.1.0 and 11.2.0, so those older versions build from source |
| CPM.cmake | the fmt, spdlog and Catch2 sources in its source cache |
| conan_server | a private Conan server you can start inside a session (user demo, password demo) |
Asking for anything else would need the internet, so some lessons show you the honest error that produces (a missing binary, a failed download). Those errors are worth learning to read: you'll see them in real life too. Two more conventions:
- Conan sessions pass
-c tools.build:jobs=1so builds run one job at a time and print the same lines on every machine. In your own projects you can leave it out. - When Conan can't find a binary in its cache, it asks the remotes. With no network that's an error, so sessions that explore missing binaries pass
-nr(--no-remote) or runconan remote disable conancenterfirst. - Each session starts in an empty home directory, so it creates its files with
cat > file <<'EOF'heredocs. Copy them into a real project as files.
A runnable model: the diamond problem
Package managers exist mostly to solve one graph problem. Your app needs spdlog and fmt; spdlog also needs fmt. If the two requirements ask for different fmt versions, someone has to decide, and in C++ you can't link both. This model walks a small graph and reports every package that is required at more than one version:
graph = {
"app/1.0": ["spdlog/1.17.0", "fmt/12.1.0", "catch2/3.16.0"],
"spdlog/1.17.0": ["fmt/12.1.0"],
"catch2/3.16.0": [],
"fmt/12.1.0": [],
}
def walk(node, path, seen):
for dep in graph.get(node, []):
name, version = dep.split("/")
seen.setdefault(name, {}).setdefault(version, []).append(" -> ".join(path + [dep]))
walk(dep, path + [dep], seen)
return seen
def report(root):
for name, versions in sorted(walk(root, [root], {}).items()):
status = "OK" if len(versions) == 1 else "CONFLICT"
print(f"{name:<7} {status:<8} {', '.join(sorted(versions))}")
report("app/1.0")
print("--- spdlog now wants fmt 11.2.0")
graph["spdlog/1.17.0"] = ["fmt/11.2.0"]
graph["fmt/11.2.0"] = []
report("app/1.0")catch2 OK 3.16.0
fmt OK 12.1.0
spdlog OK 1.17.0
--- spdlog now wants fmt 11.2.0
catch2 OK 3.16.0
fmt CONFLICT 11.2.0, 12.1.0
spdlog OK 1.17.0
Real tools handle the conflict differently: Conan stops with a version conflict unless you override it, vcpkg picks one version for everything from its baseline, and FetchContent/CPM silently use whichever declaration came first. You'll see each of these in action.
Test yourself
Why can't a C++ package manager just ship one binary per library version, like many npm packages?
- C++ libraries are too large
- The binary must match the OS, architecture, compiler, standard library, build type and options of the consumer
- Binaries are illegal to redistribute
- CMake can only build from source
Which approach downloads and builds dependencies' source during CMake's configure step, without any binary reuse?
- Conan 2
- vcpkg with binary caching
- FetchContent / CPM.cmake
- apt
In the diamond model, what is the conflict?
- catch2 is required twice
- fmt is required at two different versions through two paths
- spdlog depends on itself
- The app has no dependencies