compiler.version 应填 MSVC 工具集对应的数字版本号(如 VS2022 填 193),而非 Visual Studio 年份或 MSVC 主版本号;必须与 PATH 中实际 cl.exe 版本、CMake runtime 设置及远端二进制一致,否则导致链接错误或重复编译。

conan profile 里 compiler.version 到底填什么
填错 compiler.version 是 Windows 下 Conan 找不到匹配二进制、反复触发源码编译的最常见原因。它不等于 Visual Studio 版本号,也不等于 MSVC 工具集编号的直觉写法。
真实对应关系是:Visual Studio 2022 → MSVC 14.3(即 compiler.version=193),Visual Studio 2019 → MSVC 14.2(即 compiler.version=192),Visual Studio 2017 → MSVC 14.1(即 compiler.version=191)。
-
compiler.version=17或compiler.version=2022是错的,Conan 不识别这种写法 - 用
cl.exe /?查看实际版本:输出首行类似Microsoft (R) C/C++ Optimizing Compiler Version 19.39.34720 for x64,取前三位193 - 若混用 VS2022 和旧 profile(如
192),Conan 会认为这是两个不同编译器,导致依赖无法复用
profile 必须和你实际调用的 cl.exe 对齐
Conan 不关心你装了几个 VS,只认当前 PATH 中生效的 cl.exe。如果你用 VS2022 的 x64 工具命令行,但 profile 写了 compiler.version=192,链接阶段大概率报 LNK2038: mismatch detected for 'RuntimeLibrary' 或找不到 .lib。
- 先确认环境:在终端运行
where cl,看路径是否指向MSVC\14.39.34720\bin\Hostx64\x64\cl.exe这类路径 - 再生成 profile:
conan profile detect --name vs2022_x64,它会自动填对compiler.version - 手动改 profile 后,务必用
conan profile show vs2022_x64核对全部字段,尤其compiler.runtime(dynamic或static)必须和项目 CMake 设置一致
Debug/Release 配置必须显式指定 build_type
Windows 上 MSVC 是多配置生成器(VS Solution),但 Conan 的 host profile 只能有一个 build_type。这意味着你不能靠 CMake GUI 切 Debug/Release 来“覆盖” profile 设置——Conan 安装依赖时已按 profile 固定的 build_type 拉包。
- 要同时支持 Debug 和 Release,得建两个 profile:
vs2022_x64_debug和vs2022_x64_release,仅build_type不同 - 运行
conan install时必须显式传--profile:build vs2022_x64_release --profile:host vs2022_x64_release,双 profile 模式下不能省略--profile:host - 如果漏掉
--profile:host,Conan 默认用 default profile,极易导致 Release 项目链接到 Debug 版 OpenSSL 等库,出现LNK2005重定义错误
runtime 和 cppstd 的坑比 version 还隐蔽
compiler.runtime 和 compiler.cppstd 看似简单,但错配后往往不报错、只在运行时崩溃或链接失败。
-
compiler.runtime=dynamic对应/MD,static对应/MT;若你的 CMake 用set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreadedDLL"),profile 就必须是dynamic -
compiler.cppstd=17表示要求所有依赖用 C++17 编译,但某些老库(如 zlib 1.2.11)不支持,会构建失败;建议新项目统一用20,老项目保守用14 - 修改 profile 后,之前安装的包不会自动失效,必须加
--build=missing或删~/.conan2/p下对应 package ID 目录,否则仍可能复用错版本
cl.exe 路径、CMake runtime 设置、Conan profile、到远端仓库可用的二进制——全部落在同一套维度组合里。少一个对齐,后面就是链接器给你发的长篇错误报告。


















