0
$\begingroup$

Rosanswers logo

Hello,I want to cross compile rospackage for arm.I do following the website http://answers.ros.org/question/191070/compile-roscore-for-arm-board/ . I have created rostoolchain.cmake file like this:

cmake_minimum_required(VERSION 2.4.6)
include($ENV{ROS_ROOT}/core/rosbuild/rostoolchain.cmake)
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_C_COMPILER /opt/freescale/usr/local/gcc-4.6.2-glibc-2.13-linaro-multilib-2011.12/fsl-linaro-toolchain/bin/arm-linux-gcc)
set(CMAKE_CXX_COMPILER /opt/freescale/usr/local/gcc-4.6.2-glibc-2.13-linaro-multilib-2011.12/fsl-linaro-toolchain/bin/arm-linux-g++)
set(CMAKE_FIND_ROOT_PATH /opt/freescale/usr/local/gcc-4.6.2-glibc-2.13-linaro-multilib-2011.12/fsl-linaro-toolchain)
set(CMAKE_LIBRARY_PATH /opt/freescale/usr/local/gcc-4.6.2-glibc-2.13-linaro-multilib-2011.12/fsl-linaro-toolchain/lib /home/znzx/boost/lib /opt/ros/hydro/lib)
set(CMAKE_INCLUDE_PATH  /home/znzx/boost/include /opt/ros/hydro/include /usr/include) 
set(BOOST_LIBRARY  /home/znzx/boost/lib)
set(BOOST_INCLUDE  /home/znzx/boost/include)
set(BOOST_ROOT /home/znzx/boost)
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)
When I excute `$./src/catkin/bin/catkin_make_isolated -DCMAKE_TOOLCHAIN_FILE=/home/znzx/catkin_ws/src/rostoolchain.cmake`

I got the following errors:

-- Looking for include files CMAKE_HAVE_PTHREAD_H - found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE 
-- Found gtest sources under '/usr/src/gtest': gtests will be built
CMake Error at cmake/assert.cmake:17 (message):
  

  Assertion failed: check for file existence, but filename
  (RT_LIBRARY-NOTFOUND) unset.  Message: RT Library

Call Stack (most recent call first):
  cmake/tools/rt.cmake:42 (assert_file_exists)
  cmake/all.cmake:148 (include)
  CMakeLists.txt:8 (include)


-- Configuring incomplete, errors occurred!
<== Failed to process package 'catkin': 
  Command 'cmake /home/znzx/ros_catkin_ws/src/catkin -DCATKIN_DEVEL_PREFIX=/home/znzx/ros_catkin_ws/devel_isolated/catkin -DCMAKE_INSTALL_PREFIX=/home/znzx/ros_catkin_ws/install_isolated -DCMAKE_TOOLCHAIN_FILE=/home/znzx/catkin_ws/src/rostoolchain.cmake' returned non-zero exit status 1

Reproduce this error by running:
==> cd /home/znzx/ros_catkin_ws/build_isolated/catkin && cmake /home/znzx/ros_catkin_ws/src/catkin -DCATKIN_DEVEL_PREFIX=/home/znzx/ros_catkin_ws/devel_isolated/catkin -DCMAKE_INSTALL_PREFIX=/home/znzx/ros_catkin_ws/install_isolated -DCMAKE_TOOLCHAIN_FILE=/home/znzx/catkin_ws/src/rostoolchain.cmake

Command failed, exiting.

What is RT library? How can I do to solve the problem? Please help me.thank you very much


Originally posted by Alice63 on ROS Answers with karma: 63 on 2015-04-22

Post score: 4


Original comments

Comment by inspire on 2017-01-20:
I'v got exactly the same problem. Did you solve it in the meantime?

Comment by jkolb on 2017-08-23:
Did you ever figure this out? I'm hitting the same problem.

Comment by taogashi on 2017-11-13:
The same error...

Comment by pbeeson on 2018-01-20:
I am also seeing this for certain build structures. It seems to be a non-deterministic catkin issue not related to the CMake, but somehow related to the topology.

Comment by mateus-amarante on 2018-02-01:
Similar error here. Did someone solve the problem? I think it might be related to this pull request: https://github.com/ros/catkin/pull/811.

Comment by antipattern on 2018-02-06:
Does your rootfs provide an librt.so? If so, where?

Comment by mateus-amarante on 2018-02-06:
In my case, the librt.so is in ${CMAKE_FIND_ROOT_PATH}/lib/arm-linux-gnueabihf/. When I add *link_directories(${CMAKE_FIND_ROOT_PATH}/usr/lib/arm-linux-gnueabihf)* (the file is there), I still get the same error.

Comment by antipattern on 2018-02-07:
Then I am lost, I thought your toolchain might not include the multiarch dirs by itself, but if you add them manually it should work. Does crosscompiling a regular CMake project which links against librt work with your toolchain?

Comment by mateus-amarante on 2018-02-09:
It works fine with a simple CMake project. I tried to compile a catkin project again with CMAKE_LIBRARY_ARCHITECTURE=arm-linux-gnueabihf in the toolchain file. I got the error: "file '/mnt/bbgroot/usr/lib/arm-linux-gnueabihf/librt.so' does not exist. Message: RT Library". The lib is there.

Comment by antipattern on 2018-02-14:
I am not sure what is happening in this case. If the library is indeed at that location, I do not see how the assertion might fail. How did you check the file exists?

Comment by mateus-amarante on 2018-02-14:
ls /mnt/bbgroot/usr/lib/arm-linux-gnueabihf/librt.so outputs librt.so. For now, I commented the assertion step in .../catkin/cmake/tools/rt.cmake. I'm still getting errors, but I'll try a little more.

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

I came up with a temporary solution. My target device is a BeagleBone Black.

1) You need to create a simple toolchain.cmake file like the following one

# this one is important
SET(CMAKE_SYSTEM_NAME Linux)
#this one not so much
SET(CMAKE_SYSTEM_VERSION 1)

# Set the target architecture
set(CMAKE_LIBRARY_ARCHITECTURE arm-linux-gnueabihf)

# specify the cross compiler
SET(CMAKE_C_COMPILER   /usr/bin/arm-linux-gnueabihf-gcc)
SET(CMAKE_CXX_COMPILER /usr/bin/arm-linux-gnueabihf-g++)

# where is the target environment 
SET(CMAKE_FIND_ROOT_PATH "/path/to/target-root") # no slash "/" at the end

# search for programs in the build host directories
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# for libraries and headers in the target directories
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

# Set compiler flag
SET(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} --sysroot=${CMAKE_FIND_ROOT_PATH}")
SET( CMAKE_CXX_FLAGS  "${CMAKE_CXX_FLAGS} --sysroot=${CMAKE_FIND_ROOT_PATH}" )

2) Setup your catkin profile. Let's suppose you want to create a profile called "cross" and the toolchain.cmake file is located in src folder.

catkin config --profile cross --extend /path/to/target-root/opt/ros/kinetic
catkin config --profile cross --cmake-args  -DCMAKE_TOOLCHAIN_FILE=`pwd`/src/toolchain.cmake

It's also good to set an specific location for "build", "devel" and "install" folders.

3) In the CMakeLists.txt of your project, place the following code before you link your targets to catkin_LIBRARIES:

if(CMAKE_CROSSCOMPILING) 
    set(fixed_catkin_libraries)
    foreach (dir ${catkin_LIBRARIES})
        foreach(root_path ${CMAKE_FIND_ROOT_PATH})
            if(dir MATCHES "^${root_path}/") # assume CMAKE_FIND_ROOT_PATH has no "/" at the end
                list(APPEND fixed_catkin_libraries ${dir})
            else()
                list(APPEND fixed_catkin_libraries "${root_path}${dir}")
            endif()
        endforeach()
    endforeach()
    set(catkin_LIBRARIES ${fixed_catkin_libraries})
endif()

**4) Compile your project. If you get errors, try running touch src/toolchain.cmake

References:

[1] https://cmake.org/Wiki/CMake_Cross_Compiling

[2] https://github.com/AutoModelCar/catkin_ws_user

[3] https://github.com/ros/catkin/pull/811


Originally posted by mateus-amarante with karma: 26 on 2018-03-21

This answer was ACCEPTED on the original site

Post score: 1

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.