docker内外连通ros_docker搭建ros-indigo-arm交叉编译环境

本文介绍了如何在x86系统上利用docker搭建ROS Indigo的ARM交叉编译环境,以提高在ARM设备上编译ROS应用的效率。主要步骤包括:安装docker和ROS ARM版本,备份x86库,设置交叉编译工具链,修改配置文件,以及进行编译。
摘要由CSDN通过智能技术生成

ROS运行环境:ARM ubuntu14.04 + ROS indigo

在arm环境下编译ros应用程序,速度极慢,无法忍受,尝试在x86机器上搭建docker+ros交叉编译环境。

交叉编译环境的搭建主要参考:

1 ARM ubuntu环境上安装arm-indigo版本,后面需要将这个arm版本copy到交叉编译环境上

2 x86环境上安装docker

3 下载docker-ros镜像, 加载启动docker-ros镜像

4 安装 sudo apt-get install g++-arm-linux-gnueabihf

5 将docker环境中中x86版本的indigo替换成arm版本的indigo,

替换之前需要备份x86版本indigo的lib,因为这些库文件在运行ros时是需要的。

将x86版本indigo的lib保存到localpath目录下,设置export LD_LIBRARY_PATH=localpath,

实现运行ros命令时使用x86的lib库。

6 将arm环境下的库文件/头文件 copy到docker环境中,目录可以自己设定比如:/$ENV{HOME}/cross-compiling/ubuntu-rootfs

7 配置rostoolchain.cmake文件

#File rostoolchain.cmake

set(CMAKE_SYSTEM_NAME Linux)

set(CMAKE_C_COMPILER /usr/bin/arm-linux-gnueabihf-gcc)

set(CMAKE_CXX_COMPILER /usr/bin/arm-linux-gnueabihf-g++)

set(CMAKE_FIND_ROOT_PATH /opt/ros/indigo $ENV{HOME}/cross-compiling/ubuntu-rootfs)

set(CMAKE_LIBRARY_PATH $ENV{HOME}/cross-compiling/ubuntu-rootfs/usr/lib/arm-linux-gnueabihf $ENV{HOME}/cross-compiling/ubuntu-rootfs/usr/lib $ENV{HOME}/cross-compiling/ubuntu-rootfs/lib $ENV{HOME}/cross-compiling/ubuntu-rootfs/usr/local/lib)

set(CMAKE_INCLUDE_PATH $ENV{HOME}/cross-compiling/ubuntu-rootfs/usr/include $ENV{HOME}/cross-compiling/ubuntu-rootfs/usr/local/include)

set(LD_LIBRARY_PATH $ENV{HOME}/cross-compiling/ubuntu-rootfs/usr/lib/arm-linux-gnueabihf $ENV{HOME}/cross-compiling/ubuntu-rootfs/usr/lib $ENV{HOME}/cross-compiling/ubuntu-rootfs/lib $ENV{HOME}/cross-compiling/ubuntu-rootfs/usr/local/lib)

set(PYTHON_EXECUTABLE /usr/bin/python)

set(PCL_ROOT $ENV{HOME}/cross-compiling/ubuntu-rootfs/usr)

set(CMAKE_CROSSCOMPILING true)

message("${CMAKE_CROSSCOMPILING}")

# Have to set this one to BOTH, to allow CMake to find rospack

set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY)

set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)

set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

View Code

8 修改/opt/ros/indigo/share/catkin/cmake/tools/rt.cmake

该文件的第34行

if(NOT (APPLE OR WIN32 OR MINGW OR ANDROID))修改为if(NOT (APPLE OR WIN32 OR MINGW OR ANDROID OR UNIX))

9 个人理解cmake交叉编译过程就是修改cmake搜索链接库文件位置的过程,正常编译会搜索x86库文件做在位置,

交叉编译需要将搜索位置切换到目标架构需要的库文件存放位置,比如/$ENV{HOME}/cross-compiling/ubuntu-rootfs

实现方法:

修改catkin_INCLUDE_DIRS catkin_LIBRARY_DIRS,将这两个变量中指向x86系统的位置,修改为指向交叉编译依赖文件存放位置

/opt/ros/indigo/share/catkin/cmake/catkinConfig.cmake

这个文件末增加如下处理:

list(APPEND catkin_INCLUDE_DIRS ${CMAKE_INCLUDE_PATH})

list(APPEND catkin_LIBRARY_DIRS ${CMAKE_LIBRARY_PATH})

set(catkin_LIBRARIES_tmp ${catkin_LIBRARIES})

set(catkin_LIBRARIES "")

foreach(catkinlib ${catkin_LIBRARIES_tmp})

string(LENGTH ${catkinlib} lengths)

if (${lengths} GREATER 12)

string(SUBSTRING ${catkinlib} "/" 12 result)

string(COMPARE EQUAL ${result} "/usr/lib/lib" compareResult)

if (${compareResult})

string(REPLACE "/usr/lib/lib" "$ENV{HOME}/cross-compiling/ubuntu-rootfs/usr/lib/lib" result_tem ${catkinlib})

list(APPEND catkin_LIBRARIES ${result_tem})

else()

list(APPEND catkin_LIBRARIES ${catkinlib})

endif()

else()

list(APPEND catkin_LIBRARIES ${catkinlib})

endif()

endforeach()

View Code

10 编译命令

catkin_make -DCMAKE_TOOLCHAIN_FILE=/$filepath/rostoolchain.cmake

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值