根本原因是conan未配置远程源或证书验证失败,导致无法连接center.conan.io;需执行conan remote add center https://center.conan.io,并处理ssl错误或添加国内镜像源。

conan install 报错 “Unable to find package” 或 “No remote available”
根本原因不是包真不存在,而是 Conan 不知道该去哪找——它默认只认 center.conan.io,但首次运行时可能没配置远程源,或证书验证失败导致连接被拒。
常见现象包括:ERROR: HTTPSConnectionPool(host='center.conan.io', port=443): Max retries exceeded、conan search xxx 返回空、conan install 卡住不动。
- 先确认远程源是否已添加:
conan remote list,若无center条目,立刻执行:conan remote add center https://center.conan.io - 若仍报 SSL 错误(尤其在 Linux/macOS 上),需手动安装证书:
conan config install https://github.com/conan-io/conanclientcert.git - 国内用户建议额外加镜像源(如清华源)并设为默认:
conan remote add tsinghua https://mirrors.tuna.tsinghua.edu.cn/conan/ --force,再用conan remote update tsinghua --url=https://mirrors.tuna.tsinghua.edu.cn/conan/确保地址有效
ARM macOS / RISC-V Linux 下 conan install --build=missing 仍失败
ConanCenter 的预编译二进制目前对 Apple Silicon(arm64)和新兴架构支持不全,--build=missing 会触发本地编译,但很多包的 conanfile.py 没适配新架构,直接报 Invalid setting 'os' value: 'Macos' 或找不到 compiler.libcxx。
- 检查当前 profile 是否匹配目标平台:
conan profile show default,重点关注arch(应为armv8或arm64)、os(Macos)、compiler(apple-clang)三者是否一致 - 若 profile 不对,用
conan profile new default --detect重新生成;若检测不准,手动编辑~/.conan2/profiles/default,补全[settings]块,例如:arch=armv8、compiler.libcxx=libc++ - 某些老包(如
openssl/1.1.1w)根本不声明armv8支持,此时只能换新版(如openssl/3.2.0)或改用conan create自己 patchconanfile.py中的supported_archs判断逻辑
CMake 找不到 find_package(XXX) 对应的 Config.cmake
不是 Conan 没装包,而是 CMake 没读到 Conan 生成的配置文件。现代 Conan(v2+)默认用 CMakeDeps + CMakeToolchain,不再生成 conanbuildinfo.cmake,旧教程里 include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) 已失效。
- 确保
conan install命令中指定了-g CMakeDeps -g CMakeToolchain,且输出目录(--output-folder)与 CMake 构建目录一致 - CMakeLists.txt 中必须在
project()后立即加载 toolchain:cmake_minimum_required(VERSION 3.23)+project(MyApp)+include(${CMAKE_BINARY_DIR}/conan_toolchain.cmake) - 调用
find_package()前,得先 include deps 文件:include(${CMAKE_BINARY_DIR}/xxx-release-x86_64-data.cmake)(文件名由CMakeDeps生成,含 build_type 和 arch)
依赖传递时子包头文件或库路径缺失
你写了 requires = "zlib/1.2.13", "mylib/1.0@user/stable",但 mylib 自身依赖 fmt,结果编译时提示 fmt/format.h: No such file or directory——这不是 mylib 没打包好,而是它的 conanfile.py 没把 fmt 声明为 requires,或者没在 package() 中显式 self.copy 头文件。
- 检查上游包的
conanfile.py:其requires块必须包含所有编译期依赖(哪怕只是头文件),不能靠下游项目“顺手加上” - 上游包的
package()方法里,必须有类似self.copy("*.h", dst="include", src="include")和self.copy("*.a", dst="lib", keep_path=False),否则 Conan 不会把东西放进最终包结构 - 本地开发时,用
conan create . user/testing打包后,立刻用conan inspect "mylib/1.0@user/testing" --raw=package_id验证包 ID 是否稳定;再用conan download "mylib/1.0@user/testing"+conan info查看实际布局
profile 是 per-machine 的,不是 per-project 的。同一份 conanfile.py 在 Intel Mac 和 M2 Mac 上,必须用各自生成的 profile 运行 conan install,否则 conan.lock 里记录的二进制 hash 就对不上,CI 里尤其容易因此拉取错包。











