NixOS下如何配置Conan使用本地CMake而非自行编译?
在NixOS上配置Conan使用本地CMake替代自动下载版本
问题描述
在NixOS上使用Conan 2.5.0安装依赖时,执行conan install conanfile.txt --build=missing遇到错误:Conan自动下载的CMake为动态链接版本,无法在NixOS环境运行。错误日志如下:
➜ conan install conanfile.txt --build=missing ======== Installing packages ======== -------- Downloading 14 packages -------- cmake/3.30.5: Retrieving package 63fead0844576fc02943e16909f08fcdddd6f44b from remote 'conancenter' cmake/3.30.5: Downloading 44.0MB conan_package.tgz cmake/3.30.5: Decompressing 44.0MB conan_package.tgz cmake/3.30.5: Package installed 63fead0844576fc02943e16909f08fcdddd6f44b cmake/3.30.5: Downloaded package revision e7bca794d221e787672baaed17ddbc3f # ... cmake/3.30.5: Appending PATH environment variable: /home/jorge/.conan2/p/cmake472b88369c9bf/p/bin cmake/3.30.5: Appending PATH environment variable: /home/jorge/.conan2/p/cmake472b88369c9bf/p/bin # ... -------- Installing package joltphysics/3.0.1 (21 of 32) -------- joltphysics/3.0.1: Building from source joltphysics/3.0.1: Package joltphysics/3.0.1:3f7fd406790cc7bc8b3903b7793684e958c409a3 joltphysics/3.0.1: Copying sources to build folder joltphysics/3.0.1: Building your package in /home/jorge/.conan2/p/b/joltpc788376fa4e1a/b joltphysics/3.0.1: Calling generate() joltphysics/3.0.1: Generators folder: /home/jorge/.conan2/p/b/joltpc788376fa4e1a/b/build/Release/generators joltphysics/3.0.1: CMakeToolchain generated: conan_toolchain.cmake joltphysics/3.0.1: CMakeToolchain generated: /home/jorge/.conan2/p/b/joltpc788376fa4e1a/b/build/Release/generators/CMakePresets.json joltphysics/3.0.1: Generating aggregated env files joltphysics/3.0.1: Generated aggregated env files: ['conanbuild.sh', 'conanrun.sh'] joltphysics/3.0.1: Calling build() joltphysics/3.0.1: Apply patch (conan): Fix CMakeLists: no warnings as errors, allow shared, add install target, and add profile & debug_renderer options joltphysics/3.0.1: Running CMake.configure() joltphysics/3.0.1: RUN: cmake -G "Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE="generators/conan_toolchain.cmake" -DCMAKE_INSTALL_PREFIX="/home/jorge/.conan2/p/b/joltpc788376fa4e1a/p" -DCMAKE_POLICY_DEFAULT_CMP0091="NEW" -DCMAKE_BUILD_TYPE="Release" "/home/jorge/.conan2/p/b/joltpc788376fa4e1a/b/src/Build" Could not start dynamically linked executable: cmake NixOS cannot run dynamically linked executables intended for generic linux environments out of the box. For more information, see: https://nix.dev/permalink/stub-ld joltphysics/3.0.1: ERROR: Package '3f7fd406790cc7bc8b3903b7793684e958c409a3' build failed joltphysics/3.0.1: WARN: Build folder /home/jorge/.conan2/p/b/joltpc788376fa4e1a/b/build/Release ERROR: joltphysics/3.0.1: Error in build() method, line 141 cmake.configure(build_script_folder=os.path.join(self.source_folder, "Build")) ConanException: Error 127 while executing
当前Conan profile:
➜ conan profile show Host profile: [settings] arch=x86_64 build_type=Release compiler=gcc compiler.cppstd=gnu17 compiler.libcxx=libstdc++11 compiler.version=13 os=Linux Build profile: [settings] arch=x86_64 build_type=Release compiler=gcc compiler.cppstd=gnu17 compiler.libcxx=libstdc++11 compiler.version=13 os=Linux
项目conanfile.txt内容:
[requires] eastl/3.21.12 joltphysics/3.0.1 diligent-core/api.252009 [generators] CMakeDeps
解决方案
1. 确认本地CMake路径
先获取NixOS上已安装CMake的绝对路径:
which cmake
通常输出为/run/current-system/sw/bin/cmake(系统级安装)或~/.nix-profile/bin/cmake(用户级安装)。
2. 配置Conan使用本地CMake
有两种常用方式:
方式一:修改Conan Profile(永久生效)
编辑默认Profile文件(~/.conan2/profiles/default),在文件末尾添加以下配置,替换为你实际获取到的CMake路径:
[conf] tools.cmake.cmaketoolchain:cmake_program=/run/current-system/sw/bin/cmake [buildenv] PATH=/run/current-system/sw/bin:$PATH
方式二:执行命令时临时指定(单次生效)
在conan install命令中直接通过-c参数指定CMake路径:
conan install conanfile.txt --build=missing -c tools.cmake.cmaketoolchain:cmake_program=$(which cmake)
3. 验证配置
重新执行conan install命令,此时Conan会跳过下载cmake包,直接使用你本地安装的3.29.2版本进行依赖构建。
内容的提问来源于stack exchange,提问作者shackra
相关产品推荐
相关产品推荐

