Cross Compile ROS and openCV for Drive AGX Orin

Please provide the following info (tick the boxes after creating this topic):
Software Version
DRIVE OS 6.0.4 (rev. 1)
DRIVE OS 6.0.4 SDK
other

Target Operating System
Linux
QNX
other

Hardware Platform
DRIVE AGX Orin Developer Kit (940-63710-0010-D00)
DRIVE AGX Orin Developer Kit (940-63710-0010-C00)
DRIVE AGX Orin Developer Kit (not sure its number)
other

SDK Manager Version
1.9.10816
other

Host Machine Version
native Ubuntu Linux 20.04 Host installed with SDK Manager
native Ubuntu Linux 20.04 Host installed with DRIVE OS Docker Containers
native Ubuntu Linux 18.04 Host installed with DRIVE OS Docker Containers
other

Hello, we are trying to cross compile an application depending on ROS and openCV, for the drive AGX Orin board. Is there any reference on this? Currently i am getting this error, when cross-compiling.

aarch64-linux-g++: WARNING: unsafe header/library path used in cross-compilation: '-I/usr/include/opencv4'
In file included from /opt/ros/noetic/include/ros/ros.h:38,
                 from /home/nvidia/lisa-drive-apps/apps/src/l********/src/main.cpp:10:
/opt/ros/noetic/include/ros/time.h:58:10: fatal error: boost/math/special_functions/round.hpp: No such file or directory
   58 | #include <boost/math/special_functions/round.hpp>
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make[4]: *** [src/********/CMakeFiles/********.dir/build.make:63: src/**********/CMakeFiles/**********.dir/src/main.cpp.o] Error 1
make[3]: *** [CMakeFiles/Makefile2:1185: src/lisa_carla_camera_listener/CMakeFiles/lisa_carla_camera_listener.dir/all] Error 2
make[2]: *** [Makefile:130: all] Error 2
make[1]: *** [Makefile:62: build-arm64] Error 2
make: *** [Makefile:70: arm64-all] Error 2

We use the latest ngc driveos docker container for compiliation, and cross compilation works, with all the samples.

I have seen some threads on cross compiling openCV and ROS (dw-ros), but I am wondering, how to get it working with DriveOS 6.04.

Dear @christopher.tuch,
We do not officially support ROS and opencv on DRIVE AGX Orin. So we have not tested compiling them.
May I know what functionalities you are using from OpenCV.

Dear @SivaRamaKrishnaNV

Currently the cv_bridge to convert incoming Images via ROS to dwImages. Do you have an suggestion/idea on how to try it?

Dear @christopher.tuch,
May I know the use case. So that I can check if it can be implemented using Nvmedia/DW APIs.

@SivaRamaKrishnaNV

For example this Application Pipeline:

ROS image sensor_msgs → cv::Mat → dwImageCPU

Please see if Convert cv::Mat to dwImageCPU helps.

@VickNV
Yes this helped, i already do it like this. I still need to Cross Compile ROS in order to run the application on the Drive Board. I was able to follow the instructions on the GitHub - NVIDIA/dw-ros: ROS cross-compilation with DriveWorks repo. And change everything to match ros noetic and DriveOS 6.0.4
I am using a different compiler since the one in the current DriveOS Toolchain, is not working for me, it points to a toolchain_wrapper binary and somehow this does not work for me. When following the instructions i get trouble compiling the class_loader at this step:

cross compile ROS

src/catkin/bin/catkin_make_isolated --install -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=~/Downloads/Toolchain-V5L.cmake 

I don’t know if you are familiar with the instructions of this GitHub - NVIDIA/dw-ros: ROS cross-compilation with DriveWorks repo, but any idea is much appreciated.

I haven’t tried to cross compile ROS on DRIVE OS 6.0.x. Please help elaborate on why its toolchain isn’t working.


These are the compilers in the DriveOS Toolchain Folder located at ~/nvidia/nvidia_sdk/DRIVE_OS_6.0.4_SDK_Linux_DRIVE_AGX_ORIN_DEVKITS/DRIVEOS/toolchains/aarch64–glibc–stable-2022.03-1/bin

When compiling I get the Error, that the Compiler (which is specified in the Toolchain-V5L.cmake) is not a full path to a compiler, or when using those aarch64-buildroot-linux-gnu compilers, that the compiler are broken and cannot be used to build the project.

Therefore I switched to use the Compiler in ~/nvidia/nvidia_sdk/DRIVE_OS_6.0.4_SDK_Linux_DRIVE_AGX_ORIN_DEVKITS/DRIVEOS/drive-linux/filesystem/targetfs/bin which seems to be working.

I installed ros-noetic-ros-base with a QEMU environment in ~/nvidia/nvidia_sdk/DRIVE_OS_6.0.4_SDK_Linux_DRIVE_AGX_ORIN_DEVKITS/DRIVEOS/drive-linux/filesystem/targetfs

following the steps in the nvidia/dw-ros repo

My Toolchain looks like this. Which is also based on the nvidia/dw-ros repo, but with changes to the TOOLCHAIN, to match the folder structure of 6.0.x

set(CMAKE_SYSTEM_NAME Linux) 
# Specify the cross compiler 
set(TOOLCHAIN "$ENV{HOME}/nvidia/nvidia_sdk/DRIVE_OS_6.0.4_SDK_Linux_DRIVE_AGX_ORIN_DEVKITS/DRIVEOS/drive-linux/filesystem/targetfs") 
# set(TOOLCHAIN "$ENV{HOME}/nvidia/nvidia_sdk/DRIVE_OS_6.0.4_SDK_Linux_DRIVE_AGX_ORIN_DEVKITS/DRIVEOS/toolchains/armv5-eabi--glibc--stable-2020.08-1") 
set(CMAKE_CXX_COMPILER "${TOOLCHAIN}/bin/c++") 
set(CMAKE_C_COMPILER "${TOOLCHAIN}/bin/cc") 
# Targetfs path 
set(ROS_SYSROOT "$ENV{HOME}/nvidia/nvidia_sdk/DRIVE_OS_6.0.4_SDK_Linux_DRIVE_AGX_ORIN_DEVKITS/DRIVEOS/drive-linux/filesystem/targetfs") 
# Library paths 
set(LD_PATH "${ROS_SYSROOT}/usr/lib/aarch64-linux-gnu") 
set(LD_PATH_EXTRA "/lib/aarch64-linux-gnu") 
# setup compiler for cross-compilation 
set(CMAKE_CXX_FLAGS           "-fPIC"               CACHE STRING "c++ flags") 
set(CMAKE_C_FLAGS             "-fPIC"               CACHE STRING "c flags") 
set(CMAKE_SHARED_LINKER_FLAGS ""                    CACHE STRING "shared linker flags") 
set(CMAKE_MODULE_LINKER_FLAGS ""                    CACHE STRING "module linker flags") 
set(CMAKE_EXE_LINKER_FLAGS    ""                    CACHE STRING "executable linker flags") 
set(CMAKE_FIND_ROOT_PATH ${ROS_SYSROOT}) 
# Set compiler flags 
set(CMAKE_SHARED_LINKER_FLAGS   "--sysroot=${CMAKE_FIND_ROOT_PATH} -L${LD_PATH} -L${LD_PATH_EXTRA} -Wl,-rpath,${LD_PATH} -Wl,-rpath,${LD_PATH_EXTRA} -Wl,-rpath,${LD_PATH} -Wl,-rpath,${LD_PATH_EXTRA} ${CMAKE_SHARED_LINKER_FLAGS}") 
set(CMAKE_MODULE_LINKER_FLAGS   "--sysroot=${CMAKE_FIND_ROOT_PATH} -L${LD_PATH} -L${LD_PATH_EXTRA} -Wl,-rpath,${LD_PATH} -Wl,-rpath,${LD_PATH_EXTRA} -Wl,-rpath,${LD_PATH} -Wl,-rpath,${LD_PATH_EXTRA} ${CMAKE_SHARED_LINKER_FLAGS}") 
set(CMAKE_EXE_LINKER_FLAGS      "--sysroot=${CMAKE_FIND_ROOT_PATH} -L${LD_PATH} -L${LD_PATH_EXTRA} -Wl,-rpath,${LD_PATH} -Wl,-rpath,${LD_PATH_EXTRA} -Wl,-rpath,${LD_PATH_EXTRA} ${CMAKE_EXE_LINKER_FLAGS}") 
set(CMAKE_C_FLAGS "-fPIC --sysroot=${CMAKE_FIND_ROOT_PATH} -fpermissive -g" CACHE INTERNAL "" FORCE) 
set(CMAKE_CXX_FLAGS "-fPIC --sysroot=${CMAKE_FIND_ROOT_PATH} -fpermissive -g" CACHE INTERNAL "" FORCE) 
# Search for programs only in the build host directories 
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 
# Search for libraries and headers only in the target directories 
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 

# set system default include dir
include_directories(BEFORE SYSTEM ${ROS_SYSROOT}/usr/include ${ROS_SYSROOT}/usr/include/aarch64-linux-gnu)

I still get errors when compiling, looking like this:

Scanning dependencies of target pcl_recorder_node
[ 66%] Building CXX object CMakeFiles/pcl_recorder_node.dir/src/PclRecorder.cpp.o
[ 66%] Building CXX object CMakeFiles/pcl_recorder_node.dir/src/main.cpp.o
[100%] Linking CXX executable /home/chrtuch/carla-ros-bridge/catkin_ws/devel_isolated/pcl_recorder/lib/pcl_recorder/pcl_recorder_node
/usr/bin/ld: skipping incompatible /home/chrtuch/nvidia/nvidia_sdk/DRIVE_OS_6.0.4_SDK_Linux_DRIVE_AGX_ORIN_DEVKITS/DRIVEOS/drive-linux/filesystem/targetfs/usr/lib/aarch64-linux-gnu/libpthread.so when searching for -lpthread
/usr/bin/ld: skipping incompatible /home/chrtuch/nvidia/nvidia_sdk/DRIVE_OS_6.0.4_SDK_Linux_DRIVE_AGX_ORIN_DEVKITS/DRIVEOS/drive-linux/filesystem/targetfs/usr/lib/aarch64-linux-gnu/libpthread.a when searching for -lpthread
/usr/bin/ld: skipping incompatible /lib/aarch64-linux-gnu/libpthread.so when searching for -lpthread
/usr/bin/ld: skipping incompatible /lib/aarch64-linux-gnu/libpthread.a when searching for -lpthread
/usr/bin/ld: skipping incompatible /home/chrtuch/nvidia/nvidia_sdk/DRIVE_OS_6.0.4_SDK_Linux_DRIVE_AGX_ORIN_DEVKITS/DRIVEOS/drive-linux/filesystem/targetfs/usr/lib/aarch64-linux-gnu/libpthread.so when searching for -lpthread
/usr/bin/ld: skipping incompatible /home/chrtuch/nvidia/nvidia_sdk/DRIVE_OS_6.0.4_SDK_Linux_DRIVE_AGX_ORIN_DEVKITS/DRIVEOS/drive-linux/filesystem/targetfs/usr/lib/aarch64-linux-gnu/libpthread.a when searching for -lpthread
/usr/bin/ld: skipping incompatible /lib/aarch64-linux-gnu/libpthread.so when searching for -lpthread
/usr/bin/ld: skipping incompatible /lib/aarch64-linux-gnu/libpthread.a when searching for -lpthread
/usr/bin/ld: /usr/lib/aarch64-linux-gnu/libuuid.so: error adding symbols: file in wrong format
collect2: error: ld returned 1 exit status

BTW: I have a simlink /usr/lib/aarch64-linux-gnu to /home/chrtuch/nvidia/nvidia_sdk/DRIVE_OS_6.0.4_SDK_Linux_DRIVE_AGX_ORIN_DEVKITS/DRIVEOS/drive-linux/filesystem/targetfs/lib/aarch64-linux-gnu
What kind of error is this? I cant find a good answer on google, is it due to the lib beeing the wrong architecture or version? I dont know.

Thanks for looking into this.

What are the issues? Can’t they be fixed by modify the cmake file?

Are you trying to build on the target system instead of cross-compilation?

Dear @VickNV

This issue is already resolved, by using compilers from the ~/nvidia/nvidia_sdk/DRIVE_OS_6.0.4_SDK_Linux_DRIVE_AGX_ORIN_DEVKITS/DRIVEOS/drive-linux/filesystem/targetfs/bin directory.

I did try this, and it worked. But it is not the preferable way. Cross Compiling would be nice. I do use the Compilers in the targetfs directory, on my host PC in order to cross compile.
I dont think the compiler is the issue. The the compiler in the targetfs directory seems to work, as it can compile a few applications without problems.

This error only appears when trying to cross compile. On the target system the compilation works fine. The toolchain points to the correct LD Path and all the include paths are set correctly to the directories, the QEMU virtualization installed the libs and headers. Any ideas why it still wont compile?

I was asking what’s the issue of cross-compiling with the original toolchain (~/nvidia/nvidia_sdk/DRIVE_OS_6.0.4_SDK_Linux_DRIVE_AGX_ORIN_DEVKITS/DRIVEOS/toolchains). I don’t think ~/nvidia/nvidia_sdk/DRIVE_OS_6.0.4_SDK_Linux_DRIVE_AGX_ORIN_DEVKITS/DRIVEOS/drive-linux/filesystem/targetfs/bin is to be used under x86.

-- VIBRANTE_PDK = /drive/drive-linux
CMake Error at cmake/Toolchain-V5L.cmake:76 (message):
  Can't open /drive/drive-linux/lib-target/version-nv-(pdk/sdk).txt for PDK
  branch detection
Call Stack (most recent call first):
  /usr/share/cmake-3.16/Modules/CMakeDetermineSystem.cmake:93 (include)
  CMakeLists.txt:46 (project)


CMake Error: CMake was unable to find a build program corresponding to "Unix Makefiles".  CMAKE_MAKE_PROGRAM is not set.  You probably need to select a different build tool.
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred!
make[1]: *** [Makefile:57: arm64] Error 1
make: *** [Makefile:70: arm64-all] Error 2

With the original Toolchain-V5l.cmake file

I haven’t tried it. But you may

Have you modified Toolchain-V5L.cmake according to 6.0.4 paths under ~/nvidia/nvidia_sdk?

No i did not modify the Toolchain-V5L.cmake under /usr/local/driveworks/samples/cmake/Toolchain-V5L.cmake
and i am not able to cross-compile the samples with this cmake command

cmake -B home/chrtuch/nvidia/build/build-linux-aarch64 -DCMAKE_TOOLCHAIN_FILE=/usr/local/driveworks/samples/cmake/Toolchain-V5L.cmake -DVIBRANTE_PDK=$NVIDIA_SDK/DRIVE_OS_*_SDK_Linux_DRIVE_AGX_ORIN_DEVKITS/DRIVEOS/drive-linux -S /usr/local/driveworks/samples

installed via SDK Manager.
For cross-compiling ROS i need to change the Toolchain-V5L.cmake or write my own, which I did following the guide in the dw-ros repo and changing paths according to DriveOS6.0.x installation.

For issues of cross compiling default DriveWorks samples, please create another topic.

For porting dw-ros repo to DriveWorks 5.6, yes, you have to modify files to make it happen.