CMake 无法在 Windows github actions 上构建 eigen

问题描述 投票:0回答:1

嗯,我正在开发一个 C++ 项目,其中使用 Eigen 的线性代数。

这就是我从根获取 Eigen 库的方式

CmakeLists.txt

message([STATUS] "Fetching eigen.")
block(SCOPE_FOR VARIABLES)
    set(EIGEN_BUILD_TESTING OFF)
    set(EIGEN_BUILD_PKGCONFIG OFF)
    set(EIGEN_BUILD_DOC OFF)
    FetchContent_Declare(
            Eigen
            GIT_REPOSITORY https://gitlab.com/libeigen/eigen.git
            GIT_TAG 3.4
            GIT_SHALLOW TRUE
            GIT_PROGRESS TRUE
    )
    FetchContent_MakeAvailable(Eigen)
endblock()

然后我可以在 ubuntu-22.04 和 windows-latest 上构建和测试 github 操作。

在 Windows 上构建的说明如下(仅在构建开始之前复制):

# This starter workflow is for a CMake project running on a single platform. There is a different starter workflow if you need cross-platform coverage.
# See: https://github.com/actions/starter-workflows/blob/main/ci/cmake-multi-platform.yml
name: CMake build and test on Windows

on:
  push:
    branches: [ "master" ]
  pull_request:
    branches: [ "master" ]

env:
  # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
  BUILD_TYPE: Release

jobs:
  build:
    name: build and test
    # The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac.
    # You can convert this to a matrix build if you need cross-platform coverage.
    # See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
    runs-on: windows-latest

    steps:
      - uses: actions/checkout@v4

      - name: Set reusable strings
        id: strings
        shell: bash
        run: |
          echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT"
          echo "bin-output-dir=${{ github.workspace }}/bin" >> "$GITHUB_OUTPUT"

      - name: Configure CMake
        run: >
          cmake -B ${{ steps.strings.outputs.build-output-dir }}
          -DCMAKE_CXX_COMPILER=msvc
          -DCMAKE_C_COMPILER=msvc
          -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }}
          -S ${{ github.workspace }}

问题

Linux 构建成功,但 Windows 构建失败,并在“配置 CMake”步骤中出现了一个轻微意外的错误。错误说:

[STATUS]Fetching pugixml.
[STATUS]Fetching eigen.
-- The C compiler identification is MSVC 19.39.33523.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Tools/MSVC/14.39.33519/bin/Hostx64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Performing Test EIGEN_COMPILER_SUPPORT_CPP11
-- Performing Test EIGEN_COMPILER_SUPPORT_CPP11 - Failed
-- Performing Test COMPILER_SUPPORT_std=cpp03
-- Performing Test COMPILER_SUPPORT_std=cpp03 - Failed
-- Performing Test standard_math_library_linked_to_automatically
-- Performing Test standard_math_library_linked_to_automatically - Failed
-- Performing Test standard_math_library_linked_to_as_m
-- Performing Test standard_math_library_linked_to_as_m - Failed
CMake Error at build/_deps/eigen-src/CMakeLists.txt:136 (message):
  Can't link to the standard math library.  Please report to the Eigen
  developers, telling them about your platform.


-- Configuring incomplete, errors occurred!
Error: Process completed with exit code 1.

有人知道什么吗?

注:

在我将 OpenXLSX 作为子模块添加到项目中之前,这用于编译。现在却没有了。根据自述文件,该库应该能够使用 msvc(我正在使用)构建。

c++ cmake eigen
1个回答
0
投票
-- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Tools/MSVC/14.39.33519/bin/Hostx64/x64/cl.exe  - skipped
  1. 您应该省略显式编译器选择。它混淆了构建系统。
  2. 显式使用 CMake 生成器,如
    cmake -G "Visual Studio 17 2022" -A x64
    。这将生成一个完整的 MSVS 解决方案来构建并避免以 MinGW 等方式调用 MSVC 编译器时的情况。
  3. 在下载之前执行清理,然后明确设置包含路径,如此处所述。
  4. 尝试使用仅下载策略和
    find_package
    功能,如下所示:
    find_package (Eigen3 REQUIRED NO_MODULE)
© www.soinside.com 2019 - 2024. All rights reserved.