【问题标题】:How to use Boost and pybind11 on GitHub Actions如何在 GitHub Actions 上使用 Boost 和 pybind11
【发布时间】:2021-11-14 08:49:19
【问题描述】:

我正在尝试为使用 Boost、Eigen 和 pybind11 的代码设置 GitHub 操作。 CMakeLists.txt 和 .yml 文件如下。我遇到以下问题: CMake 在 Linux 版本上找不到 Boost,在 Windows 代码上只安装了 64 位 Boost。 Eigen 似乎没有给我任何问题,并且在 macOS 上代码运行良好。所以我有以下问题:

  1. 我应该如何在 GitHub 操作上安装 Boost?我在下面的 .yml 文件上尝试了三个选项(使用文件中注释掉的操作,使用 Conda 和在 Linux 上使用 apt-get)。在适用于所有操作系统的 GitHub 上安装 Boost 操作的推荐方法是什么?

  2. 如何让 CMake 在 Linux 上找到 Boost?使用完全相同的代码,CMake 能够在 macOS 和 Windows 上找到 Boost,但在 Linux 上却不行。我想我需要设置一些环境变量,但不确定哪个以及如何设置?有没有人有 .yml 和 CMakeLists.txt 的工作示例,CMake 可以在其中找到 Boost on Linux?

  3. 当操作在 Windows 上运行时,它在 Windows 64 位上运行良好,但如果在 32 位上失败,因为安装的 Boost 是 64 位。在 Windows 32 位上运行时如何安装 32 位 Boost?

这是 CMakeLists.txt 文件:

cmake_minimum_required(VERSION 3.12)

project(Test)

cmake_policy(SET CMP0054 NEW)

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

add_subdirectory(pybind11)

find_package(Boost COMPONENTS chrono thread serialization REQUIRED)

include_directories (
  /usr/local/include
  ${CMAKE_SOURCE_DIR}/include
  ${USER_INCLUDE_PATH} )

link_directories (
  /usr/local/lib
  ${USER_LIBRARY_PATH} )

pybind11_add_module(_test test.cpp)

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

这是 GitHub 操作 .yml 文件:

name: Build wheels

on:
  push:
    branches:
      - master

jobs:
  # Build wheels for macOS, Linux, and Windows
  build_wheels:
    name: Wheel for ${{ matrix.os }}-cp${{ matrix.python }}
    runs-on: ${{ matrix.os }}

    strategy:
      fail-fast: false
      matrix:
        os: [windows-latest, ubuntu-latest, macos-latest]
        python: [36, 37, 38, 39]

    steps:
      # - name: Install boost
      #   uses: MarkusJx/install-boost@v2.0.0
      #   id: install-boost
      #   with:
      #     boost_version: 1.71.0
      #   if: runner.os == 'Windows'

      - name: Set up conda environment
        uses: conda-incubator/setup-miniconda@v2
        with:
          miniconda-version: "latest"
          auto-update-conda: true
          activate-environment: conda-env
        if: runner.os == 'Windows' || runner.os == 'Linux'

      - name: Install libraries for Windows
        run: |
          conda install -c conda-forge boost
          conda install -c conda-forge eigen
        shell: pwsh
        if: runner.os == 'Windows'

      - name: Install libraries for Linux
        run: |
          conda install -c conda-forge boost
          conda install -c conda-forge eigen
          # sudo apt-get update
          # sudo apt-get install libboost-all-dev
        shell: bash
        if: runner.os == 'Linux'

      - name: Install libraries for macOS
        run: |
          brew upgrade
          brew install boost
          brew install eigen
        shell: bash
        if: runner.os == 'macOS'

      - name: Checkout repository and submodules
        uses: actions/checkout@v2
        with:
          submodules: true

      - name: Set up Python
        uses: actions/setup-python@v2

      - name: Install cibuildwheel
        run: python -m pip install cibuildwheel

      - name: Build wheel
        run:
          python -m cibuildwheel --output-dir wheelhouse
        env:
          CIBW_BUILD: cp${{ matrix.python }}-*

      - name: Show files
        run: ls -lh wheelhouse
        shell: bash

      - name: Verify clean directory
        run: git diff --exit-code
        shell: bash

      - name: Upload artifacts
        uses: actions/upload-artifact@v2
        with:
          path: wheelhouse/*.whl

【问题讨论】:

  • 我应该补充一点,上面的配置(上面的 CMakeLists.txt 文件)如果安装了 Boost,代码在 Linux 机器上可以正常工作。它仅在作为 GitHub 操作运行时才会失败。
  • 您在编译或链接阶段有问题吗?
  • 编译期间。 CMake 说它在编译期间找不到 Boost。问题似乎出在命令find_package(Boost COMPONENTS chrono thread serialization REQUIRED)

标签: c++ boost cmake github-actions pybind11


【解决方案1】:

我从未在 Windows 上使用过 GitHub Actions,但对于 Linux,我的设置与您的非常相似,使用 apt-get 来安装 boost。我能看到的唯一区别是我明确告诉 CMake 在哪里寻找 Boost 的包含与

INCLUDE_DIRECTORIES( ${Boost_INCLUDE_DIR} )

【讨论】:

  • 谢谢!问题是 ${Boost_INCLUDE_DIR} 在作为 GitHub 操作运行时为空。我认为问题在于跑步者没有正确设置环境变量。正如我在上面的评论中添加的那样,CMakeLists.txt 在 Linux 机器上运行良好。
猜你喜欢
  • 2021-03-21
  • 2020-01-14
  • 2021-01-20
  • 2023-02-14
  • 2020-12-13
  • 2022-08-16
  • 2020-12-21
  • 2020-05-27
  • 2022-01-07
相关资源
最近更新 更多