ros-industrial / ros2_canopen

CANopen driver framework for ROS2
https://ros-industrial.github.io/ros2_canopen/manual/rolling/
157 stars 68 forks source link

HOW to build ros2 canopen raspberrypi4B on x86 platform with cross-compilation? #251

Open zouzhe1 opened 9 months ago

zouzhe1 commented 9 months ago

Target Device: Raspberry Pi 4B with Ubuntu 22, Local Device: x86_64 with Ubuntu 22.

Due to the limited memory on my Raspberry Pi 4B, the compilation speed of ROS 2 CANopen is extremely slow, and it often freezes.

Therefore, I intend to perform cross-compilation on my PC.

How should I proceed with cross-compilation?

It would be preferable if you could provide a binary version that can be installed using sudo.

LudoJ49 commented 9 months ago

use this to create 2G of extra swap memory...

sudo fallocate -l 2G /swapfile    # Adjust size as needed (2G in this example)
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
MichaelT800 commented 6 months ago

Since lely_core_libraries is generated for x86 architecture, you need to modify the CMakeLists.txt of this package.

add:Cross-compilation or normal compilation

if(CMAKE_CROSSCOMPILING) set(CONFIGURE_COMMAND_PREFIX . ${CMAKE_CURRENT_SOURCE_DIR}/arm64_toolchain.sh &&) set(CONFIGURE_HOST_OPTION --host=aarch64-linux-gnu) else() set(CONFIGURE_COMMAND_PREFIX "") set(CONFIGURE_HOST_OPTION "") endif()

modifications

CONFIGURE_COMMAND ${CONFIGURE_COMMAND_PREFIX} autoreconf -i && /configure ${CONFIGURE_HOST_OPTION} --prefix= --disable-cython --disable-doc --disable-tests --disable-static --disable-diag as such 截图 2024-05-13 10-22-54 The arm64_toolchain.sh file is placed in the same directory as the CMakeLists.txt file in the package, with the following contents

!/bin/sh

export CC=/usr/bin/aarch64-linux-gnu-gcc export CXX=/usr/bin/aarch64-linux-gnu-g++ export AR=/usr/bin/aarch64-linux-gnu-ar export AS=/usr/bin/aarch64-linux-gnu-as export LD=/usr/bin/aarch64-linux-gnu-ld export STRIP=/usr/bin/aarch64-linux-gnu-strip export RANLIB=/usr/bin/aarch64-linux-gnu-ranlib

Probably not the most logical thing to do, but it worked for me so I could compile x86 and arm64 separately.