I am trying to cross compile a ROS package for a Jetson nano (aarch64
) using my x86_64
PC. I am using the toolchain provided by nvidia (GCC Tool Chain for 64-bit BSP). I have been following this article for guidance
As the compiler needs boost binaries from the aarch64 system, I have mounted the nano's /usr/include/boost
into my build directory's usr/include/boost
. Here's my build directory heirachy.
.
├── gcc-4.8.5-aarch64 #<cross compiler>
│ └── install
│ ├── aarch64-unknown-linux-gnu
│ ...
├── opt #<ROS source files from nano>
│ └── ros
│ └── melodic
├── src #<test c++ code in here>
│ └── test_cpp
│ └── src
└── usr
├── include
│ └── boost #<nano's /usr/include/boost mounted in here>
└── lib
└── aarch64-linux-gnu #<nano's /usr/lib/aarch64-linux-gnu mounted in here>
When compiling, I get errors saying the compiler cannot find boost libraries.
from /home/teshan/xcompile/src/test_cpp/src/talker.cpp:1: /home/teshan/xcompile/opt/ros/melodic/include/ros/time.h:58:50:
fatal error: boost/math/special_functions/round.hpp: No such file or directory
#include <boost/math/special_functions/round.hpp>
^
compilation terminated.
I have math/special_functions/round.hpp
file inside the mounted directory usr/include/boost
. But it seems CMake cannot find it. Instead it says boost/math/special_functions/round.hpp: No such file or directory
which I think indicates it searches for boost directory in the root directory (Please correct me if I'm wrong)
I have looked at this and this answers but setting BOOST_ROOT
does not seem to have an effect. Any insight to this would be of great help
TL;DR
This is my build script
#!/bin/bash
PWD=$(pwd)
export LANG=C
source /opt/ros/melodic/setup.bash
catkin config --extend ${PWD}/opt/ros/melodic/
catkin build -j8 --cmake-args \
-DCMAKE_TOOLCHAIN_FILE=${PWD}/toolchain.cmake \
-DCMAKE_CROSS_COMPILE_PREFIX=${PWD} \
-DRT_LIBRARY=${PWD}/usr/lib/aarch64-linux-gnu/
Here's my toolchain.cmake
SET(CMAKE_SYSTEM_NAME Linux)
SET(CMAKE_C_COMPILER ${NANO_ROOT_PATH}/gcc-4.8.5-aarch64/install/bin/aarch64-unknown-linux-gnu-gcc)
SET(CMAKE_CXX_COMPILER ${NANO_ROOT_PATH}/gcc-4.8.5-aarch64/install/bin/aarch64-unknown-linux-gnu-g++)
# Below call is necessary to avoid non-RT problem.
SET(CMAKE_LIBRARY_ARCHITECTURE aarch64-linux-gnu)
SET(NANO_ROOT_PATH ${CMAKE_CURRENT_LIST_DIR})
SET(NANO_MELODIC_PATH ${NANO_ROOT_PATH}/opt/ros/melodic)
SET(CMAKE_FIND_ROOT_PATH ${NANO_ROOT_PATH} ${CATKIN_DEVEL_PREFIX})
SET(COMPILER_ROOT ${NANO_ROOT_PATH}/gcc-4.8.5-aarch64/install)
#Have to set this one to BOTH, to allow CMake to find rospack
#This set of variables controls whether the CMAKE_FIND_ROOT_PATH and CMAKE_SYSROOT are used for find_xxx() operations.
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH)
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
SET(CMAKE_PREFIX_PATH ${NANO_MELODIC_PATH} ${NANO_ROOT_PATH}/usr)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --sysroot=${NANO_ROOT_PATH}" CACHE INTERNAL "" FORCE)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --sysroot=${NANO_ROOT_PATH}" CACHE INTERNAL "" FORCE)
SET(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} --sysroot=${NANO_ROOT_PATH}" CACHE INTERNAL "" FORCE)
SET(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} --sysroot=${NANO_ROOT_PATH}" CACHE INTERNAL "" FORCE)
SET(LD_LIBRARY_PATH ${NANO_MELODIC_PATH}/lib)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
#Skip toolchain trying to build a test program first
SET(CMAKE_C_COMPILER_WORKS 1)
SET(CMAKE_CXX_COMPILER_WORKS 1)
set(BOOST_ROOT ${NANO_ROOT_PATH}/usr/include/boost)
set(COMPILER_SYSROOT ${COMPILER_ROOT}/aarch64-unknown-linux-gnu/sysroot)
include_directories(BEFORE SYSTEM ${COMPILER_SYSROOT}/usr/include/)