cmakemakefileg++cross-compilingros

cmake and g++ cross compilation looking for library in host sysroot path instead of target sysroot


I am cross-compiling a ROS application to an aarch64 system.

When building the linker is looking for the libraries in the host root path, and not in the target rootfs.

In particular, the error is:

make[2]: *** No rule to make target '/usr/lib/aarch64-linux-gnu/libboost_date_time.so.1.71.0', needed by '~/build/devel/lib/libcv_bridge.so'.  Stop.
make[1]: *** [CMakeFiles/Makefile2:951: src/CMakeFiles/cv_bridge.dir/all] Error 2

To the best of my knowledge g++ is looking for boost date_time in:

/usr/lib/aarch64-linux-gnu/libboost_date_time.so.1.71.0

But the library is in:

${ROOT_PATH}/usr/lib/aarch64-linux-gnu/libboost_date_time.so.1.71.0

This issue is not related to Boost, for example the liblog4cxx.so for rosconsole presents this problem also.

I have been carefull to set the proper variables, and this Toolchain is based on an NVIDIA provided here Also I have checked the CMAKE_FIND_ROOT_PATH, CMAKE_FIND_ROOT_PATH_MODE_PROGRAM

PD: My cmake toolchain is:

#----------------------------------------------------------------------------------
# CMake includes and configuration
#----------------------------------------------------------------------------------
SET(CMAKE_SYSTEM_NAME Linux)
SET(CMAKE_SYSTEM_PROCESSOR aarch64)
SET(CMAKE_HOST_SYSTEM_PROCESSOR x86_64)


#----------------------------------------------------------------------------------
# Complier configuration
#----------------------------------------------------------------------------------
SET(CMAKE_LIBRARY_ARCHITECTURE aarch64-linux-gnu) # Below call is necessary to avoid non-RT problem.
SET(CROSSCOMPILE TRUE)

SET(COMPILER_ROOT "$ENV{CROSS_COMPILE}")
SET(TROOT_PATH  $ENV{ROOTFS_ORIN})

# Specify the cross compiler 
set(CMAKE_CXX_COMPILER  ${COMPILER_ROOT}/bin/aarch64-buildroot-linux-gnu-g++)
set(CMAKE_C_COMPILER    ${COMPILER_ROOT}/bin/aarch64-buildroot-linux-gnu-gcc)

#----------------------------------------------------------------------------------
# ROS configuration
#----------------------------------------------------------------------------------
SET(NOETIC_PATH ${ROOT_PATH}/opt/ros/noetic)
SET(CMAKE_CROSS_COMPILE_PREFIX ${NOETIC_PATH})

# Library paths 
set(LD_PATH        ${ROOT_PATH}/usr/lib/aarch64-linux-gnu)
set(LD_PATH_EXTRA  ${ROOT_PATH}/lib/aarch64-linux-gnu)
set(LD_PATH_EXTRA2 ${ROOT_PATH}/lib/)
set(LD_ROS_PATH    ${NOETIC_PATH})
set(CMAKE_PATH     ${LD_PATH}/cmake/)

#----------------------------------------------------------------------------------
# Directory configuration
#----------------------------------------------------------------------------------
SET(CMAKE_PREFIX_PATH ${LD_PATH} ${LD_PATH_EXTRA} ${LD_ROS_PATH} ${CMAKE_PATH})
SET(CMAKE_MODULE_PATH ${LD_PATH} ${LD_PATH_EXTRA} ${LD_ROS_PATH} ${CMAKE_PATH})

# setup compiler for cross-compilation 
SET(CMAKE_SYSROOT           "${ROOT_PATH}" CACHE INTERNAL "" FORCE)
SET(CMAKE_SYSROOT_COMPILE   "${ROOT_PATH}" CACHE INTERNAL "" FORCE)
SET(CMAKE_SYSROOT_LINK      "${ROOT_PATH}" CACHE INTERNAL "" FORCE)

SET(CMAKE_C_FLAGS   "${CMAKE_CXX_FLAGS} -L${LD_PATH} -L${LD_PATH_EXTRA} -L ${LD_ROS_PATH}")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -L${LD_PATH} -L${LD_PATH_EXTRA} -L ${LD_ROS_PATH}")


set(CMAKE_EXPORT_COMPILE_COMMANDS=ON)
set(CMAKE_FIND_ROOT_PATH ${ROOT_PATH} ${NOETIC_PATH})
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
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 compiler flags 
set(CMAKE_SHARED_LINKER_FLAGS   "-L${LD_PATH} -L${LD_PATH_EXTRA} -L ${LD_ROS_PATH} -Wl,-rpath,${LD_PATH} -Wl,-rpath,${LD_PATH_EXTRA} -Wl,-rpath,${LD_PATH_EXTRA} -Wl,-rpath,${LD_ROS_PATH} ${CMAKE_SHARED_LINKER_FLAGS}")
set(CMAKE_MODULE_LINKER_FLAGS   "-L${LD_PATH} -L${LD_PATH_EXTRA} -L ${LD_ROS_PATH} -Wl,-rpath,${LD_PATH} -Wl,-rpath,${LD_PATH_EXTRA} -Wl,-rpath,${LD_PATH_EXTRA} -Wl,-rpath,${LD_ROS_PATH} ${CMAKE_MODULE_LINKER_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS      "-L${LD_PATH} -L${LD_PATH_EXTRA} -L ${LD_ROS_PATH} -Wl,-rpath,${LD_PATH} -Wl,-rpath,${LD_PATH_EXTRA} -Wl,-rpath,${LD_PATH_EXTRA} -Wl,-rpath,${LD_ROS_PATH} ${CMAKE_EXE_LINKER_FLAGS}")

#----------------------------------------------------------------------------------
# Library Versions
#----------------------------------------------------------------------------------

SET(OPENCV_VERSION 4.5)
SET(BOOST_VERSION  1.71.0)
SET(PKG_CONFIG_EXECUTABLE /usr/bin/pkg-config)
SET(PYTHON_EXECUTABLE /usr/bin/python3.8)

# Flags for libraries
include_directories(BEFORE SYSTEM ${ROOT_PATH}/usr/include)
include_directories("${ROOT_PATH}/usr/include/aarch64-linux-gnu")

I am expecting the compiler to find the libraries in the target sysroot


Solution

  • The issue was a reference to catkin_LIBRARIES that was injecting some reference to the libraries located in the target root filesystem.

    The process to debug this issue was removing the different libraries and building until I found that catkin was the only responsible of the make errors.

    Thanks to @Tsyvarev for the help.