Closed19

ROS 2をM2 mac miniにインストールする

jojo43jojo43

System requirements
We currently support macOS Mojave (10.14).

https://docs.ros.org/en/iron/Installation/Alternatives/macOS-Development-Setup.html

jojo43jojo43

とりあえず最初の方はこのドキュメントに書かれている通りの手順で問題なさそう

jojo43jojo43

brewで色々インストール

brew install asio assimp bison bullet cmake console_bridge cppcheck \
  cunit eigen freetype graphviz opencv openssl orocos-kdl pcre poco \
  pyqt5 python qt@5 sip spdlog osrf/simulation/tinyxml1 tinyxml2
jojo43jojo43

勝手にインストールされてしまうPython3.12をアンインストール

brew uninstall --ignore-dependencies python@3.12
jojo43jojo43

pipで依存関係をインストールしようとしたら、

python3 -m pip install -U \
  argcomplete catkin_pkg colcon-common-extensions coverage \
  cryptography empy flake8 flake8-blind-except==0.1.1 flake8-builtins \
  flake8-class-newline flake8-comprehensions flake8-deprecated \
  flake8-docstrings flake8-import-order flake8-quotes \
  importlib-metadata jsonschema lark==1.1.1 lxml matplotlib mock mypy==0.931 netifaces \
  nose pep8 psutil pydocstyle pydot pygraphviz pyparsing==2.4.7 \
  pytest-mock rosdep rosdistro setuptools==59.6.0 vcstool

エラーが出てきた

ERROR: Could not build wheels for pygraphviz, which is required to install pyproject.toml-based projects
jojo43jojo43

このissueでもこの記事でも、

python -m pip install \
    --global-option=build_ext \
    --global-option="-I$(brew --prefix graphviz)/include/" \
    --global-option="-L$(brew --prefix graphviz)/lib/" \
    pygraphviz

を実行するように言われているけど、同様のエラーが出た

Failed to build pygraphviz
ERROR: Could not build wheels for pygraphviz, which is required to install pyproject.toml-based projects
jojo43jojo43

こちらのコメントの通りにやったら pygraphviz のインストールは成功した

python3 -m pip install \
                --config-settings="--global-option=build_ext" \
                --config-settings="--global-option=-I$(brew --prefix graphviz)/include/" \
                --config-settings="--global-option=-L$(brew --prefix graphviz)/lib/" \
                pygraphviz
jojo43jojo43

今度は成功した

python3 -m pip install -U \
  argcomplete catkin_pkg colcon-common-extensions coverage \
  cryptography empy flake8 flake8-blind-except==0.1.1 flake8-builtins \
  flake8-class-newline flake8-comprehensions flake8-deprecated \
  flake8-docstrings flake8-import-order flake8-quotes \
  importlib-metadata jsonschema lark==1.1.1 lxml matplotlib mock mypy==0.931 netifaces \
  nose pep8 psutil pydocstyle pydot pygraphviz pyparsing==2.4.7 \
  pytest-mock rosdep rosdistro setuptools==59.6.0 vcstool
jojo43jojo43

ここからはM2固有の手順になりそうなので、こちらこちらの記事を参考に進める

ソースの用意

git clone https://github.com/TakanoTaiga/ros2_m1_native.git
cd ros2_m1_native
mkdir src
vcs import src < ros2.repos

ビルド

colcon build --symlink-install --merge-install --cmake-args \
            -DBUILD_TESTING=OFF \
            -DTHIRDPARTY=FORCE \
            -DCMAKE_BUILD_TYPE=Release
jojo43jojo43

ビルド結果

Summary: 82 packages finished [49.0s]
  1 package failed: rviz_ogre_vendor
  5 packages aborted: foonathan_memory_vendor ignition_math6_vendor mcap_vendor uncrustify_vendor yaml_cpp_vendor
  88 packages had stderr output: ament_clang_format ament_clang_tidy ament_cmake ament_cmake_auto ament_cmake_clang_format ament_cmake_clang_tidy ament_cmake_copyright ament_cmake_core ament_cmake_cppcheck ament_cmake_cpplint ament_cmake_export_definitions ament_cmake_export_dependencies ament_cmake_export_include_directories ament_cmake_export_interfaces ament_cmake_export_libraries ament_cmake_export_link_flags ament_cmake_export_targets ament_cmake_flake8 ament_cmake_gen_version_h ament_cmake_gmock ament_cmake_google_benchmark ament_cmake_gtest ament_cmake_include_directories ament_cmake_libraries ament_cmake_lint_cmake ament_cmake_mypy ament_cmake_nose ament_cmake_pclint ament_cmake_pep257 ament_cmake_pycodestyle ament_cmake_pyflakes ament_cmake_pytest ament_cmake_python ament_cmake_target_dependencies ament_cmake_test ament_cmake_vendor_package ament_cmake_version ament_cmake_xmllint ament_copyright ament_cppcheck ament_cpplint ament_flake8 ament_index_python ament_lint ament_lint_auto ament_lint_cmake ament_mypy ament_package ament_pclint ament_pep257 ament_pycodestyle ament_pyflakes ament_xmllint domain_coordinator eigen3_cmake_module fastcdr foonathan_memory_vendor gmock_vendor gtest_vendor ignition_cmake2_vendor ignition_math6_vendor launch launch_pytest launch_testing launch_xml launch_yaml libcurl_vendor mcap_vendor osrf_pycommon osrf_testing_tools_cpp pybind11_vendor ros_environment rosidl_cli rpyutils rviz_assimp_vendor rviz_ogre_vendor shared_queues_vendor sqlite3_vendor test_interface_files test_osrf_testing_tools_cpp tinyxml2_vendor tinyxml_vendor tracetools_read tracetools_trace uncrustify_vendor urdfdom_headers yaml_cpp_vendor zstd_vendor
  248 packages not processed
[49.221s] ERROR:colcon.colcon_notification.desktop_notification.terminal_notifier:Could not find the colcon-terminal-notifier.app in the install prefix '/opt/homebrew'

rviz_ogre_vendor のビルドに失敗している

jojo43jojo43

ここでコケた模様

--- stderr: rviz_ogre_vendor                                                   
CMake Warning:
  Manually-specified variables were not used by the project:

    THIRDPARTY


patch: **** malformed patch at line 1817: 
make[2]: *** [ogre-v1.12.1-prefix/src/ogre-v1.12.1-stamp/ogre-v1.12.1-patch] Error 2
make[1]: *** [CMakeFiles/ogre-v1.12.1.dir/all] Error 2
make: *** [all] Error 2
---
Failed   <<< rviz_ogre_vendor [8.65s, exited with code 2]
jojo43jojo43

https://github.com/ros2/rviz/pull/938

このPRを参考に、 ros2_m1_native/src/ros2/rviz/rviz_ogre_vendor/pragma-patch.diff の1817行目と1824行目にスペースを追加したら、 patch: **** malformed patch at line 1817: のエラーは出なくなった

しかし依然として以下のエラーは出ている

make[2]: *** [ogre-v1.12.1-prefix/src/ogre-v1.12.1-stamp/ogre-v1.12.1-patch] Error 1
make[1]: *** [CMakeFiles/ogre-v1.12.1.dir/all] Error 2
make: *** [all] Error 2
jojo43jojo43

同じPRを参考に ros2_m1_native/src/ros2/rviz/rviz_ogre_vendor/CMakeFile.txt の191行目も変更したら、出るエラーが変わった

fatal error: 'Availability.h' file not found
jojo43jojo43

以下のコマンドを実行したら、

sudo xcode-select -s /Applications/Xcode.app/Contents/Developer

次に出てきたエラー

--- stderr: urdfdom_headers                                           
You have not agreed to the Xcode license agreements. Please run 'sudo xcodebuild -license' from within a Terminal window to review and agree to the Xcode and Apple SDKs license.
---
Failed   <<< urdfdom_headers [10.3s, exited with code 69]

言われたとおりに以下を実行し、指示通りに進める

sudo xcodebuild -license

そしてビルドをリトライしたが再び 'Availability.h' file not found が出た

jojo43jojo43

XcodeもHomebrewもインストールしてなかったので、まずそれらをインストールするところから

このスクラップは3ヶ月前にクローズされました