You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

GitHub Action Runner中CMake install目标的安装目录配置问题

问题:GitHub Runner中CMake指定安装目录失败

我想在GitHub Runner中执行make install,需要先设置安装目录路径,但操作后出现错误。原CMake工作流步骤如下:

- name: Configure CMake
  run: cmake -B ${{github.workspace}}/build -DBUILD_EXAMPLES=OFF -DBUILD_FORTRAN_MODULE=OFF -CMAKE_BUILD_PREFIX=<path-to-the-install-dir>

- name: Build
  run: cmake --build ${{github.workspace}}/build  

- name: Install
  run: make install

当设置安装目录为/home/runner/work/时,CI报错:

Run cmake -B /home/runner/work/xxx/xxx/build -DBUILD_EXAMPLES=OFF -DBUILD_FORTRAN_MODULE=OFF -CMAKE_BUILD_PREFIX=/home/runner/work/
  cmake -B /home/runner/work/xxx/xxx/build -DBUILD_EXAMPLES=OFF -DBUILD_FORTRAN_MODULE=OFF -CMAKE_BUILD_PREFIX=/home/runner/work/
  shell: /usr/bin/bash -e {0}
loading initial cache file MAKE_BUILD_PREFIX=/home/runner/work/
CMake Error: Error processing file: /home/runner/work/xxx/xxx/MAKE_BUILD_PREFIX=/home/runner/work
-- The CXX compiler identification is GNU 11.3.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring incomplete, errors occurred!
See also "/home/runner/work/xxx/xxx/build/CMakeFiles/CMakeOutput.log".
Error: Process completed with exit code 1.

错误原因

CMake指定安装目录的正确参数是-DCMAKE_INSTALL_PREFIX,你写错了两个关键地方:

  • 缺少参数前缀-D,导致CMake把-CMAKE_BUILD_PREFIX当成缓存文件路径处理
  • 参数名错误,应该是CMAKE_INSTALL_PREFIX而非CMAKE_BUILD_PREFIX

修正后的工作流

方案1:修正参数后使用make install

将Configure命令中的错误参数替换为标准-DCMAKE_INSTALL_PREFIX,同时建议用GitHub工作区变量指定路径(避免硬编码):

- name: Configure CMake
  run: cmake -B ${{github.workspace}}/build -DBUILD_EXAMPLES=OFF -DBUILD_FORTRAN_MODULE=OFF -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/install

- name: Build
  run: cmake --build ${{github.workspace}}/build  

- name: Install
  run: make install -C ${{github.workspace}}/build

方案2:使用cmake --install(更跨平台)

CMake 3.15+支持直接用cmake --install执行安装,无需调用make,兼容性更好:

- name: Configure CMake
  run: cmake -B ${{github.workspace}}/build -DBUILD_EXAMPLES=OFF -DBUILD_FORTRAN_MODULE=OFF -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/install

- name: Build
  run: cmake --build ${{github.workspace}}/build  

- name: Install
  run: cmake --install ${{github.workspace}}/build

内容的提问来源于stack exchange,提问作者Mr T

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.10 01:31:04