Conan 默认使用 Release 构建类型,不显式指定 -s build_type=Debug 时不会拉取 Debug 二进制或生成调试符号,导致调试失败或链接错误;必须通过 profile 或命令行明确设置 build_type,并与 CMake 的 CMAKE_BUILD_TYPE 严格对齐。

Conan 默认走 Release,不显式指定 build_type 就不会拉 Debug 二进制,也不会生成带调试符号的依赖 —— 这是绝大多数人编译失败或无法调试的根源。
conan install 必须带 -s build_type=Debug 或 -s build_type=Release
Conan 不会从当前 CMake 的 CMAKE_BUILD_TYPE 自动推断构建类型;它只认自己命令行或 profile 里声明的 build_type 设置。
- 不加
-s build_type=...时,Conan 用 profile 中定义的默认值(通常是Release) - 即使你后续在 CMake 中传
-DCMAKE_BUILD_TYPE=Debug,如果conan install拉的是 Release 二进制,链接会失败或运行时崩溃 - 命令示例:
conan install . -s build_type=Debug --build=missing -if build - Windows + MSVC 多配置生成器(如 Visual Studio)需额外加
--config Debug,但前提是conan install已用-s build_type=Debug拉对了包
profile 里设死 build_type 更稳妥,尤其多环境协作时
手动每次敲 -s build_type=... 容易漏、难复现。把构建类型写进 profile 是工程化底线。
- 运行
conan profile detect --name mydebug生成基础 profile,再编辑~/.conan2/profiles/mydebug - 确保里面有明确一行:
build_type=Debug(或Release) - 安装时直接用:
conan install . -pr=mydebug --build=missing -if build - 不同 profile 可共存(如
mydebug/myrelease),避免来回改参数
CMake 和 Conan 的 build_type 必须对齐,否则 toolchain 错、链接错、符号丢
CMakeToolchain 生成器会读取 Conan 的 build_type 设置来决定是否加 -g、是否关优化。两者不一致,等于让编译器“一边开调试一边做 O3”。
- Linux/macOS 单配置:CMake 命令必须与 Conan
build_type一致,例如:cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=build/conan_toolchain.cmake - Windows MSVC 多配置:CMake 生成时不传
CMAKE_BUILD_TYPE,靠--config Debug切;但前提是conan install已用-s build_type=Debug下载对应二进制 - 检查是否对齐:运行
conan install . -pr=mydebug --dry-run,看输出里build_type是否真为Debug
最容易被忽略的一点:Conan 的 build_type 不仅影响你自己项目的编译标志,还决定它从远端拉哪个二进制 —— 而远端可能根本没有你想要的 build_type 组合,这时 --build=missing 就会触发本地编译,但若你的 profile 缺少 compiler.libcxx 等关键 setting,编译照样失败。


















