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

如何在GitHub Actions中配置Boost、pybind11及Eigen编译环境

问题解答

1. 全操作系统兼容的Boost推荐安装方式

  • 放弃conda安装方案,conda的库路径默认不纳入CMake全局搜索路径,跨架构适配性差,容易出现找不到依赖的问题
  • 分系统对应安装方案:
    • macOS:直接使用homebrew官方源安装,路径统一无适配问题
    • Linux(Ubuntu):使用apt官方源安装libboost-all-dev,版本匹配度高
    • Windows:使用专门的Boost安装Action,可直接指定版本和架构,不需要手动配置环境变量
  • 该方案覆盖三大系统,不需要额外适配路径,稳定性高于你之前尝试的三种方案

2. Linux环境下CMake识别Boost的配置方法

你遇到的问题核心有两个:一是conda安装的Boost路径不在CMake默认搜索范围内,二是cibuildwheel默认在独立的manylinux容器内执行构建,宿主环境安装的依赖不会同步到容器中。

配置修改点:

CMakeLists.txt修改

删除硬编码的/usr/local/include和/usr/local/lib路径,新增Boost搜索相关的配置:

cmake_minimum_required(VERSION 3.12)

project(Test)

cmake_policy(SET CMP0054 NEW)

if(MSVC)
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /permissive-")
endif()

# 新增Boost搜索配置
set(Boost_USE_STATIC_LIBS OFF)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
# 调试时可打开下面的配置查看搜索路径
# set(Boost_DEBUG ON)

add_subdirectory(pybind11)

find_package(Boost COMPONENTS chrono thread serialization REQUIRED)

include_directories (
  ${CMAKE_SOURCE_DIR}/include
  ${USER_INCLUDE_PATH}
  ${Boost_INCLUDE_DIRS}
)

link_directories (
  ${USER_LIBRARY_PATH}
  ${Boost_LIBRARY_DIRS}
)

pybind11_add_module(_test test.cpp)

target_link_libraries (
  _test PRIVATE
  Boost::chrono
  Boost::thread
  Boost::serialization
)

GitHub Actions配置修改

在cibuildwheel执行前添加CIBW_BEFORE_BUILD_LINUX环境变量,在容器内提前安装Boost和Eigen:

- name: Build wheel
  run: python -m cibuildwheel --output-dir wheelhouse
  env:
    CIBW_BUILD: cp${{ matrix.python }}-*
    # 新增Linux容器内安装依赖的配置
    CIBW_BEFORE_BUILD_LINUX: |
      yum install -y boost-devel eigen3-devel

如果坚持用apt安装的方案,需要将Boost路径传递到CMake的搜索前缀:

env:
  CMAKE_PREFIX_PATH: $ENV{CONDA_PREFIX}
  BOOST_ROOT: $ENV{CONDA_PREFIX}

3. Windows 32位环境下安装32位Boost的方法

在构建矩阵中新增架构维度,使用Boost安装Action时指定对应架构即可:

矩阵修改示例:

strategy:
  fail-fast: false
  matrix:
    os: [windows-latest, ubuntu-latest, macos-latest]
    python: [36, 37, 38, 39]
    arch: [x64, x86]
    exclude:
      # 排除Linux和macOS的x86构建
      - os: ubuntu-latest
        arch: x86
      - os: macos-latest
        arch: x86

Boost安装步骤修改:

- name: Install boost
  uses: MarkusJx/install-boost@v2.0.0
  id: install-boost
  with:
    boost_version: 1.71.0
    architecture: ${{ matrix.arch }}

同时在构建时指定对应架构,cibuildwheel会自动适配32位构建环境,安装的32位Boost可被正常识别。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.03 08:06:02