$npx -y skills add mohitmishra786/low-level-dev-skills --skill conan-vcpkgC/C++ package manager skill covering Conan and vcpkg. Use when adding third-party library dependencies to C/C++ projects, managing binary compatibility, integrating with CMake, or choosing between Conan and vcpkg. Activates on queries about Conan, vcpkg, C++ dependency management
| 1 | # Conan and vcpkg |
| 2 | |
| 3 | ## Purpose |
| 4 | |
| 5 | Guide agents through C/C++ dependency management with Conan and vcpkg: declaring dependencies, integrating with CMake, managing binary compatibility, and choosing the right tool for a given project. |
| 6 | |
| 7 | ## Triggers |
| 8 | |
| 9 | - "How do I add a C++ library dependency with Conan?" |
| 10 | - "How do I use vcpkg with CMake?" |
| 11 | - "What's the difference between Conan and vcpkg?" |
| 12 | - "How do I add zlib/openssl/fmt with a package manager?" |
| 13 | - "How do I create a vcpkg.json manifest?" |
| 14 | - "My Conan package build is failing — how do I debug it?" |
| 15 | |
| 16 | ## Workflow |
| 17 | |
| 18 | ### 1. Conan vs vcpkg decision |
| 19 | |
| 20 | ```text |
| 21 | Which package manager? |
| 22 | ├── Team uses MSVC on Windows primarily → vcpkg (better MSVC integration) |
| 23 | ├── Need binary packages (no source builds in CI) → Conan (binary cache) |
| 24 | ├── Need cross-compilation support → Conan (profiles) or Zig-based builds |
| 25 | ├── Need a specific version of a package → Conan (flexible versioning) |
| 26 | ├── Quick project setup, just need it to work → vcpkg (simpler) |
| 27 | └── Open-source project, broad audience → vcpkg (GitHub-integrated) |
| 28 | ``` |
| 29 | |
| 30 | ### 2. vcpkg setup |
| 31 | |
| 32 | ```bash |
| 33 | # Clone vcpkg |
| 34 | git clone https://github.com/microsoft/vcpkg.git |
| 35 | ./vcpkg/bootstrap-vcpkg.sh # Linux/macOS |
| 36 | ./vcpkg/bootstrap-vcpkg.bat # Windows |
| 37 | |
| 38 | # Install packages (classic mode) |
| 39 | ./vcpkg/vcpkg install zlib curl openssl |
| 40 | |
| 41 | # Integrate with CMake |
| 42 | cmake -S . -B build \ |
| 43 | -DCMAKE_TOOLCHAIN_FILE=/path/to/vcpkg/scripts/buildsystems/vcpkg.cmake |
| 44 | ``` |
| 45 | |
| 46 | ### 3. vcpkg manifest mode (recommended) |
| 47 | |
| 48 | ```json |
| 49 | // vcpkg.json — place at project root |
| 50 | { |
| 51 | "name": "myapp", |
| 52 | "version": "1.0.0", |
| 53 | "dependencies": [ |
| 54 | "zlib", |
| 55 | "curl", |
| 56 | { "name": "openssl", "version>=": "3.0.0" }, |
| 57 | { "name": "boost-filesystem", "platform": "!windows" }, |
| 58 | { |
| 59 | "name": "fmt", |
| 60 | "features": ["core"] |
| 61 | } |
| 62 | ], |
| 63 | "builtin-baseline": "abc123..." |
| 64 | } |
| 65 | ``` |
| 66 | |
| 67 | ```cmake |
| 68 | # CMakeLists.txt |
| 69 | cmake_minimum_required(VERSION 3.20) |
| 70 | project(myapp) |
| 71 | |
| 72 | find_package(ZLIB REQUIRED) |
| 73 | find_package(CURL REQUIRED) |
| 74 | find_package(fmt REQUIRED) |
| 75 | |
| 76 | add_executable(myapp src/main.cpp) |
| 77 | target_link_libraries(myapp PRIVATE ZLIB::ZLIB CURL::libcurl fmt::fmt) |
| 78 | ``` |
| 79 | |
| 80 | ```bash |
| 81 | # Build — vcpkg automatically installs dependencies |
| 82 | cmake -S . -B build \ |
| 83 | -DCMAKE_TOOLCHAIN_FILE=/path/to/vcpkg/scripts/buildsystems/vcpkg.cmake |
| 84 | cmake --build build |
| 85 | ``` |
| 86 | |
| 87 | ### 4. Conan setup |
| 88 | |
| 89 | ```bash |
| 90 | # Install Conan |
| 91 | pip install conan |
| 92 | |
| 93 | # Set up default profile (detects compiler, OS) |
| 94 | conan profile detect |
| 95 | |
| 96 | # Check your profile |
| 97 | conan profile show |
| 98 | ``` |
| 99 | |
| 100 | ### 5. Conan with CMake (Conan 2.x) |
| 101 | |
| 102 | ```ini |
| 103 | # conanfile.txt |
| 104 | [requires] |
| 105 | zlib/1.3 |
| 106 | fmt/10.2.1 |
| 107 | openssl/3.2.0 |
| 108 | |
| 109 | [generators] |
| 110 | CMakeDeps |
| 111 | CMakeToolchain |
| 112 | |
| 113 | [options] |
| 114 | openssl/*:shared=False |
| 115 | ``` |
| 116 | |
| 117 | ```bash |
| 118 | # Install dependencies |
| 119 | conan install . --output-folder=build --build=missing |
| 120 | |
| 121 | # Configure and build |
| 122 | cmake -S . -B build \ |
| 123 | -DCMAKE_TOOLCHAIN_FILE=build/conan_toolchain.cmake \ |
| 124 | -DCMAKE_BUILD_TYPE=Release |
| 125 | cmake --build build |
| 126 | ``` |
| 127 | |
| 128 | ```cmake |
| 129 | # CMakeLists.txt |
| 130 | find_package(ZLIB REQUIRED) |
| 131 | find_package(fmt REQUIRED) |
| 132 | find_package(OpenSSL REQUIRED) |
| 133 | |
| 134 | add_executable(myapp src/main.cpp) |
| 135 | target_link_libraries(myapp PRIVATE |
| 136 | ZLIB::ZLIB |
| 137 | fmt::fmt |
| 138 | OpenSSL::SSL OpenSSL::Crypto |
| 139 | ) |
| 140 | ``` |
| 141 | |
| 142 | ### 6. Conan profiles for cross-compilation |
| 143 | |
| 144 | ```ini |
| 145 | # ~/.conan2/profiles/linux-arm64 |
| 146 | [settings] |
| 147 | os=Linux |
| 148 | arch=armv8 |
| 149 | compiler=gcc |
| 150 | compiler.version=12 |
| 151 | compiler.libcxx=libstdc++11 |
| 152 | build_type=Release |
| 153 | |
| 154 | [buildenv] |
| 155 | CC=aarch64-linux-gnu-gcc |
| 156 | CXX=aarch64-linux-gnu-g++ |
| 157 | |
| 158 | [tool_requires] |
| 159 | # Tools that run on build machine (x86) |
| 160 | ``` |
| 161 | |
| 162 | ```bash |
| 163 | # Cross-compile |
| 164 | conan install . \ |
| 165 | --profile:build=default \ |
| 166 | --profile:host=linux-arm64 \ |
| 167 | --output-folder=build-arm \ |
| 168 | --build=missing |
| 169 | ``` |
| 170 | |
| 171 | ### 7. conanfile.py (advanced) |
| 172 | |
| 173 | ```python |
| 174 | # conanfile.py |
| 175 | from conan import ConanFile |
| 176 | from conan.tools.cmake import CMakeToolchain, CMakeDeps, CMake |
| 177 | |
| 178 | class MyAppConan(ConanFile): |
| 179 | name = "myapp" |
| 180 | version = "1.0" |
| 181 | settings = "os", "compiler", "build_type", "arch" |
| 182 | |
| 183 | def requirements(self): |
| 184 | self.requires("zlib/1.3") |
| 185 | self.requires("fmt/10.2.1") |
| 186 | if self.settings.os == "Linux": |
| 187 | self.requires("openssl/3.2.0") |
| 188 | |
| 189 | def generate(self): |
| 190 | tc = CMakeToolchain(self) |
| 191 | tc.generate() |
| 192 | deps = CMakeDeps(self) |
| 193 | deps.generate() |
| 194 | |
| 195 | def build(self): |
| 196 | cmake = CMake(self) |
| 197 | cmake.configure() |
| 198 | cmake.build() |
| 199 | ``` |
| 200 | |
| 201 | ### 8. Common dependency lookup |
| 202 | |
| 203 | | Library | vcpkg name | Conan name | |
| 204 | |---------|-----------|-----------| |
| 205 | | zlib | `zlib` | `zlib/1.3` | |
| 206 | | OpenSSL | `openssl` | `openssl/3.2.0` | |
| 207 | | libcurl | `curl` | `libcurl/8.4.0` | |
| 208 | | {fmt} | `fmt` | `fmt/10.2.1` |