drake 与 OpenSUSE 的集成 - 错误:无法转换 std::string_view

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

我正在尝试在 OpenSUSE Leap 15.4 中从源代码构建 drake。我有一个存储库,我在其中记录我的进度。

我快到了。我必须在 10500 步中构建 ~9500 步。

这可以看作是 drake 与 OpenSUSE 的集成 - spdlog 和 fmt 的构建错误第 2 部分的后续内容

我尝试通过两种方式从源代码构建 fmt 和 spdlog 来规避此问题中提到的先前错误:

  1. 我从源代码构建了 fmt 版本 8.1.1 和 spdlog 版本 1.10.0
  2. 我从源代码构建了 fmt 版本 10.0.0 和 spdlog 版本 1.12.0

在这两种情况下我都遇到了以下错误

ERROR: /home/dan/drake/common/BUILD.bazel:569:16: Linking common/resource_tool failed: (Exit 1): gcc-10 failed: error executing command (from target //common:resource_tool) /usr/bin/gcc-10 @bazel-out/k8-opt/bin/common/resource_tool-2.params

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
/usr/bin/ld: external/spdlog/lib/libspdlog.a(spdlog.cpp.o): relocation R_X86_64_32S against `.rodata' can not be used when making a PIE object; recompile with -fPIE
/usr/bin/ld: failed to set dynamic section sizes: bad value
collect2: error: ld returned 1 exit status

我通过使用

-DCMAKE_POSITION_INDEPENDENT_CODE=TRUE
重新编译 fmt 和 spdlog 解决了这个问题。

纠正此问题后,对于上述两种方法,我得到以下(可能相同,至少相似)错误:

  1. (fmt 8.1.1 + spdlog 1.10)https://gist.github.com/hedaniel7/7dbfc20121472d82169ae9626b56c705

(小样本):

multibody/tree/multibody_tree.cc: In instantiation of 'int drake::multibody::internal::MultibodyTree<T>::NumBodiesWithName(std::string_view) const [with T = double; std::string_view = std::basic_string_view<char>]':
multibody/tree/multibody_tree.cc:3778:1:   required from here
multibody/tree/multibody_tree.cc:370:59: error: cannot convert 'std::string_view' {aka 'std::basic_string_view<char>'} to 'const key_type&' {aka 'const std::__cxx11::basic_string<char>&'}
  370 |   return static_cast<int>(rigid_bodies_.names_map().count(name));
      |                                                           ^~~~
      |                                                           |
      |                                                           std::string_view {aka std::basic_string_view<char>}
  1. (fmt 10.0.0 + spdlog 1.12.0)https://gist.github.com/hedaniel7/93d1910eadb0709a1249be7c7a1be209
multibody/tree/element_collection.cc: In instantiation of 'void drake::multibody::internal::ElementCollection<T, Element, Index>::Rename(Index, std::string) [with T = double; Element = drake::multibody::Frame; Index = drake::TypeSafeIndex<drake::multibody::FrameTag>; std::string = std::__cxx11::basic_string<char>]':
multibody/tree/element_collection.cc:160:16:   required from here
bazel-out/k8-opt/bin/multibody/tree/_virtual_includes/multibody_tree_core/drake/multibody/tree/element_collection.h:136:21: warning: unused parameter 'index' [-Wunused-parameter]
  136 |   void Rename(Index index, std::string name);
      |               ~~~~~~^~~~~

这是我用来编译 drake 的 OpenSUSE Dockerfile:

# Use OpenSUSE Leap 15.4 as base
FROM opensuse/leap:15.4

# Install vim, sudo, and other necessary tools and libraries for drake
RUN zypper --non-interactive update && \
    zypper --non-interactive install -y vim sudo git cmake make java-1_8_0-openjdk-devel \
    glib2-devel lapack-devel libX11-devel ocl-icd-devel opencl-headers patch patchelf \
    pkg-config python3-devel python3-pygame zlib-devel pkg-config eigen3-devel \
    libmumps5 mumps-devel gcc-fortran nasm wget unzip tar gzip openmpi-devel
    # spdlog-devel   spdlog-devel install spdlog-devel and fmt-devel
    # llvm-clang llvm-clang-devel not installed as there are too old

# Add the repository for GCC 10
RUN zypper addrepo -f http://download.opensuse.org/repositories/devel:/gcc/openSUSE_Leap_15.4/ devel_gcc && \
    zypper --non-interactive --gpg-auto-import-keys refresh && \
    zypper --non-interactive install -y gcc10 gcc10-c++

# Set GCC 10 as the default compiler
RUN update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 100 --slave /usr/bin/g++ g++ /usr/bin/g++-10 && \
    update-alternatives --install /usr/bin/cc cc /usr/bin/gcc 30 && \
    update-alternatives --set cc /usr/bin/gcc && \
    update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++ 30 && \
    update-alternatives --set c++ /usr/bin/g++

# Download and build fmt
RUN wget https://github.com/fmtlib/fmt/releases/download/8.0.1/fmt-8.0.1.zip && \
    unzip fmt-8.0.1.zip && \
    cd fmt-8.0.1 && \
    mkdir build && cd build && \
    cmake .. && \
    make && \
    sudo make install

# Download and build spdlog
RUN wget https://github.com/gabime/spdlog/archive/v1.6.0.tar.gz && \
    tar xzf v1.6.0.tar.gz && \
    cd spdlog-1.6.0 && \
    mkdir build && cd build && \
    cmake .. -DSPDLOG_BUILD_SHARED=ON -DCMAKE_CXX_FLAGS="-fPIC" -DSPDLOG_FMT_EXTERNAL=ON && \
    make && \
    sudo make install

# Install Bazelisk
RUN curl -L https://github.com/bazelbuild/bazelisk/releases/download/v1.7.5/bazelisk-linux-amd64 > /usr/local/bin/bazelisk && \
    chmod +x /usr/local/bin/bazelisk && \
    ln -s /usr/local/bin/bazelisk /usr/local/bin/bazel

# Download and place jchart2d-3.3.2.jar in /usr/share/java/jchart2d.jar
RUN wget https://repo1.maven.org/maven2/net/sf/jchart2d/jchart2d/3.3.2/jchart2d-3.3.2.jar -O /usr/share/java/jchart2d.jar

# Create .pc files for LAPACK and BLAS
RUN echo -e "prefix=/usr\nexec_prefix=\${prefix}\nlibdir=\${exec_prefix}/lib64\nincludedir=\${prefix}/include\n\nName: LAPACK\nDescription: Linear Algebra Package\nVersion: 3.9.0\nLibs: -L\${libdir} -llapack\nCflags: -I\${includedir}" > /usr/share/pkgconfig/lapack.pc && \
    echo -e "prefix=/usr\nexec_prefix=\${prefix}\nlibdir=\${exec_prefix}/lib64\nincludedir=\${prefix}/include\n\nName: BLAS\nDescription: Basic Linear Algebra Subprograms\nVersion: 3.9.0\nLibs: -L\${libdir} -lblas\nCflags: -I\${includedir}" > /usr/share/pkgconfig/blas.pc

# Set up the environment for user 'dan'
RUN groupadd -r dan && \
    useradd -m -s /bin/bash -r -g dan dan && \
    mkdir -p /home/dan/drake && \
    chown -R dan:dan /home/dan/drake && \
    echo "dan ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers

USER dan
ENV HOME /home/dan
WORKDIR $HOME

# Install dependencies for pyenv and Python build
RUN sudo zypper --non-interactive install -y git gcc make zlib-devel libbz2-devel libopenssl-devel readline-devel \
    sqlite3-devel python3-clang15 clang15-devel

# Install pyenv and Python 3.10
RUN git clone https://github.com/pyenv/pyenv.git $HOME/.pyenv && \
    echo 'export PYENV_ROOT="$HOME/.pyenv"' >> $HOME/.bashrc && \
    echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> $HOME/.bashrc && \
    echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n  eval "$(pyenv init --path)"\nfi' >> $HOME/.bashrc && \
    /bin/bash -c "source $HOME/.bashrc && pyenv install 3.10.0 && pyenv global 3.10.0"

# Ensure the selected Python version 3.10 is used and install PyYAML
RUN /bin/bash -c "source $HOME/.bashrc && pyenv rehash && pip install PyYAML"

# Set environment variables for GCC to ensure Bazel uses the correct version
ENV CC=/usr/bin/gcc-10
ENV CXX=/usr/bin/g++-10
ENV PYENV_ROOT $HOME/.pyenv
ENV PATH $PYENV_ROOT/shims:$PYENV_ROOT/bin:$PATH
ENV LD_LIBRARY_PATH=/usr/lib/llvm-14/lib:$LD_LIBRARY_PATH
ENV CMAKE_PREFIX_PATH=/usr/local/lib/cmake:${CMAKE_PREFIX_PATH}

有关 docker 镜像的一些附加信息:

dan@1065f1f67b07:~/drake/cmake> gcc --version
gcc (SUSE Linux) 10.5.0
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

dan@1065f1f67b07:~/drake/cmake> clang --version
clang version 15.0.7
Target: x86_64-suse-linux
Thread model: posix
InstalledDir: /usr/bin

#include <iostream>

int main() {
  #if __cplusplus == 201703L
    std::cout << "C++17\n";
  #elif __cplusplus == 201402L
    std::cout << "C++14\n";
  #elif __cplusplus == 201103L
    std::cout << "C++11\n";
  #elif __cplusplus == 199711L
    std::cout << "C++98\n";
  #else
    std::cout << "pre-standard C++\n";
  #endif
  return 0;
}
in test_std_version.cpp
outputs:
dan@1065f1f67b07:~/drake/cmake> ./test_std_version
C++14

我在 docker hub 上上传了 docker 镜像,以便可以查看并试验结果状态,并跳过漫长的编译时间。以下是使用它们的步骤:

git clone https://github.com/hedaniel7/Drake-OpenSUSE-Integration
cd Drake-OpenSUSE-Integration
git checkout 187d96d0b915473bf286a476be0bc064d62e8d31
cd DockerHub
docker pull danielhe7/drake-opensuse-integration:fmt-8.1.1-spdlog-1.10 (or danielhe7/drake-opensuse-integration:fmt-10.0.0-spdlog-1.12)
docker-compose run drake-opensuse
c++ cmake std opensuse drake
1个回答
0
投票

您使用的 Drake 版本是否包含 https://github.com/RobotLocomotion/drake/pull/21089?最近的 Drake 必须以 C++20 模式(或更新版本)构建。截至该 PR,这现在已成为项目范围内的默认设置。在此 PR 之前,C++20 的选择是特定于平台的 setup/ubuntu/source_distribution 脚本的一部分,该脚本可能在 SUSE 设置中丢失。

© www.soinside.com 2019 - 2024. All rights reserved.