ROS Resources: Documentation | Support | Discussion Forum | Service Status | Q&A

How to cross-compile ROS2 for arm64 architecture

I think this guy - @lmayencourt upstreamed the ROS2 cross-compilation can help you. :slight_smile:

Yes ROS2 can be cross-compiled :slight_smile:

You might want to have a look to:
(but python support has been removed. Only CPP support is present)

There is also the following link that may help:

1 Like

By these, cross-compilation is working.

sed -e '/py/ s/^#*/#/' -i src/ros2/rosidl_typesupport/rosidl_default_generators/CMakeLists.txt
sed -i -r 's/<build(.+?py.+?)/<\!\-\-build\1\-\->/' src/ros2/rosidl_typesupport/rosidl_default_generators/package.xml

touch \
  src/ros2/demos/AMENT_IGNORE \
  src/ros2/examples/rclpy/AMENT_IGNORE \
  src/ros2/geometry2/AMENT_IGNORE \
  src/ros2/orocos_kinematics_dynamics/AMENT_IGNORE \
  src/ros2/rclpy/AMENT_IGNORE \
  src/ros2/rcl_interfaces/test_msgs/AMENT_IGNORE \
  src/ros2/robot_model/AMENT_IGNORE \
  src/ros2/robot_state_publisher/AMENT_IGNORE \
  src/ros2/ros1_bridge/AMENT_IGNORE \
  src/ros2/rosidl/rosidl_generator_py/AMENT_IGNORE \
  src/ros2/system_tests/AMENT_IGNORE \
  src/ros2/urdfdom/AMENT_IGNORE \
  src/ros2/urdfdom_headers/AMENT_IGNORE \
  src/ros2/urdf/AMENT_IGNORE \
  src/ros2/urdfdom/AMENT_IGNORE \

src/ament/ament_tools/scripts/ build \
    --force-cmake-configure \
    --skip-packages resource_retriever \
            rviz_assimp_vendor rviz_ogre_vendor \
            rviz_yaml_cpp_vendor rviz_rendering \
            rviz_rendering_tests rviz_common \
            rviz2 rviz_default_plugins \
    --cmake-args \
    -DCMAKE_TOOLCHAIN_FILE=`pwd`/aarch64_toolchainfile.cmake \

However, ‘ExternalProject_Add’ macro could not take toolchain settings into CMake based vendor package. That is the reason why ‘resource_retriever’ package is skipped. I may spend some time to look into the issue.

It is helpful. Thank you, @pokitoz

Another question is about the statement in

No target filesystem with Python libraries is provided here, so Python is not supported (only C++).

Does that mean if I could get a ‘rootfs’ working for aarch64 I may enable python support?

Yes, I did that earlier with an arm64 Ubuntu 16.04 rootfs and it was working fine with a simple python publisher.

Yes, that’s exactly what does to cross compile ROS2 for the Raspberry Pi. The scripts in the repo fetch a Raspbian image and prepare a rootfs so that CMake will find all the dependencies and compile/link against them.

The scripts in are generic enough that they can be adapted to cross-compile for aarch64, let me have a look at it and I’ll flesh them out. What’s your target aarch64 distribution? Ubuntu?

I am working on Jetson TX2 board, which has Ubuntu 16.04 arm64 installed. I think I can ‘rsync’ to fetch back the rootfs and try to cross-compile against.

I am not family with ‘polly’ and ‘docker’ but ‘ros2_raspbian_tools’ looks pretty good. If it could work with any rootfs rather than raspbain only that will be great.

Hmmmm, if it is about a python publish, will it work with ‘multiarch’ enabled Ubuntu box. What I am trying to do is about to install ‘libpython3-dev:arm64’ package for python dev headers and libs. However, it seems ‘ament’ cannot find them in ‘/usr/include’ or ‘/usr/lib’.

Yeah, you’ll need python3-dev:arm64 because it contains the pkgconfig files for Python3 that ament uses to “discover” the location of the Python headers and libraries.

The instructions in use the changes I made to ROS2 to cross-compile it for Android and iOS (i.e., and a bunch of others). But if you want to target a Linux distro, it’s best to use a rootfs instead since you’ll end up with a complete ROS2 environment, I’m going to update the guide in the wiki to reflect that.

To setup the python support, I used an already created ubuntu-base:

And then I installed the needed packages using chroot + qemu-aarch64-static

In the toolchain file I used the variable CMAKE_SYSROOT to specify the path of my rootfs to ament/cmake and compile.

Thank you, @esteve and @pokitoz. I got cross-compilation done for Jetson TX2.

Here is a brief for who is interesting on this.

    set(CMAKE_SYSTEM_NAME Linux)
    # specify the cross compiler
    # where is the target environment

    # This assumes that pthread will be available on the target system
    # (this emulates that the return of the TRY_RUN is a return code "0"
      CACHE STRING "Result from TRY_RUN" FORCE)
  • Apt ‘sources.list’
    deb [arch=arm64] xenial main restricted
    #deb-src [arch=arm64] xenial main restricted
    deb [arch=arm64] xenial-updates main restricted
    #deb-src [arch=arm64] xenial-updates main restricted
    deb [arch=arm64] xenial-security main restricted
    #deb-src [arch=arm64] xenial-security main restricted
  • Install ‘libpython3-dev:arm64’

  • Ignore ‘rviz’ and ‘opencv’ related packages

    src/ament/ament_tools/scripts/ build \
        --force-cmake-configure \
        --skip-packages resource_retriever \
                        rviz_assimp_vendor \
                        rviz_ogre_vendor \
                        rviz_yaml_cpp_vendor \
                        rviz_rendering \
                        rviz_rendering_tests \
                        rviz_common \
                        rviz2 \
                        rviz_default_plugins \
        --cmake-args \
            -DCMAKE_TOOLCHAIN_FILE=`pwd`/aarch64_toolchainfile.cmake \
            -DTHIRDPARTY=ON \
            -DPYTHON_INCLUDE_DIR=$(python3 -c "from distutils.sysconfig import get_python_inc; print(get_python_inc() + ';' + '/usr/include')") \
            -DPYTHON_LIBRARY=$(python3 -c "import distutils.sysconfig as sysconfig; print(sysconfig.get_config_var('LIBDIR'))")/aarch64-linux-gnu/ --
1 Like

Hi jcadam, esteve,

I try to reproduce the cross-compilation of the complete stack and get some issue during the process.
I try to follow esteve approach with docker to build the rootfs based on a arm64v8 ubuntu docker image. The cmake used is similar to the one above, and I’m using esteve “build_ros2.bash” script to trigger the build.
During the process, I got the following error:
fatal error: Eigen/Core: No such file or directory
#include <Eigen/Core>

CMake ignore the manually specified location : “DEIGEN3_INCLUDE_DIR=”${RASPBERRYPI_CROSS_COMPILE_SYSROOT}/usr/include/eigen3"
and use the default “/usr/include” path:
– Using Eigen3 include dirs: /usr/include/eigen3

I’m struggling to understand why CMake ignore the specified path… Any idea ?

Hi…i am a new user here. As per my knowledge the 64-bit ARM environment is relatively new. This means that most applications, including ROS, need to be ported to the new processor. For a complicated application like ROS, this may necessitate a variety of code and environment changes to support the new computer architecture.

board assembly

Hi ChesLans,

There is no issue to build ROS2 for aarch64. You can follow the wiki instruction on your aarch64 machine and build the complete stack, it will just take some time =)
For cross-compilation, you can build a subset of ROS2 by following the instruction here.
@jcadam and @esteve already have successfully cross-compile the complete ROS2 for raspi (arm 32) and the Jetson TX2 (arm 64).

FYI to the community, none of the above mentioned approaches work with the release of Crystal without a good deal of digging into the scripts to address moved or added dependencies like python-catkin-pkg-modules, and others. At least I haven’t been able to find a working solution…so I’m going at it from scratch. As soon as I have it, I’ll post.

1 Like

Hi @binary42,

A new documentation page just get merged explaining how to achieve cross-compilation of the Crystal release, based on the assets available at ros2/cross_compile

Please let me know if you have any issue with it !

It sounds like you have achieved building the ROS2 libs for Android. Unfortunately, the first link is dead. Can you pleas point me to the latest documentation to this topic.

I don’t know which link you’re referring to, could you be more specific? Thanks.