ROS编译catkin使⽤说明
1. catkin_make 与cmake的关系
程序在cmake编译是这样的流程, cmake指令依据你的 ⽂件,⽣成makefiles⽂件,make再依据此makefiles⽂件编译链接⽣成可执⾏⽂件. catkin_make是将cmake与
make的编译⽅式做了⼀个封装的指令⼯具, 规范了⼯作路径与⽣成⽂件路径.
cmake标准流程
# 在⼀个CMake项⽬⾥
$ mkdir build
$ cd build
$ cmake ..
$ make
$ make install # (可选)
catkin_make 的流程
# In a catkin workspace
$ catkin_make
$ catkin_make install # (可选)
如果源码不在默认⼯作空间,需要指定编译路径:
# In a catkin workspace
$ catkin_make --source my_src
手抄报心理健康$ catkin_make install --source my_src # (optionally)
2 catkin_make
&&
catkin_make默认的路径信息
在catkin_make运⾏后终端输出⽂件部分解析
#基本路径
Ba path: /home/ur/catkin_ws
Source space: /home/ur/catkin_ws/src
国画是什么
Build space: /home/ur/catkin_ws/build
Devel space: /home/ur/catkin_ws/devel
Install space: /home/ur/catkin_ws/install
#catkin_make 封装运⾏中cmake运⾏的情况
Running command: "cmake /home/ur/catkin_ws/src -DCATKIN_DEVEL_PREFIX=/home/ur/catkin_ws/devel -DCMAKE_INSTALL_PREFIX=/home/ur/catkin_ws/install -DCMAKE_RUNTIME_OUTPUT_DIRECTORY=/home/ur/catkin_ws/ #编译⼯具查找
-
- Using CATKIN_DEVEL_PREFIX: /tmp/catkin_ws/devel
-- Using CMAKE_PREFIX_PATH: /opt/ros/kinetic
-- This workspace overlays: /opt/ros/kinetic
#编译的包
<pre name="code"class="cpp"> #catkin_make 封装运⾏中make运⾏的情况
#### Running command: "make -j4" in "/home/ur/catkin_ws/build"
layout :ros⼯作空间⽂件系统结构
workspace_folder/ --WORKSPACE
src/ --SOURCE SPACE
--This is symlinked to catkin/ake
package_1/
<
...
package_n/
<
build/ --BUILD SPACE(this is where build system is invoked, not necessarily within workspace)
CATKIN_IGNORE --Marking the folder to be ignored when crawling for packages (necessary when source
space is in the root of the workspace, the file is emtpy)
#此选项可⽤于忽略某个包编译
devel/ --DEVEL SPACE (targets go here, parameterizable, but defaults to peer of Build Space)
# ⽣成⼆值库可执⾏⽂件
bin/
etc/
/include/
lib/
share/
.catkin --Marking the folder as a development space (the file contains a micolon parated list of Source space paths)
#
env.bash
tup.bash
tup.sh
...
install/ --INSTALL SPACE (this is where installed targets for test installations go, not necessarily within workspace)
bin/
etc/
include/
lib/
share/
.catkin --Marking the folder as an install space (the file is emtpy)
env.bash
tup.bash -- Environment tup file for Bash shell
tup.sh -- Environment tup file for Bourne shell
...
/
opt/
ros/
kinetic/
tup.bash -- Environment tup file for Bash shell
tup.sh -- Environment tup file for Bourne shell
tup.zsh -- Environment tup file for zshell
...
⼯作空间
源空间
编译空间
开发空间
安装空间 -DCMAKE_INSTALL_PREFIX=/any/directory cmake默认是/usr/local
系统安装空间 /opt/ros/ROSDISTRO
结果空间 source RESULT-SPACE/tup.sh #类似扫描安装空间与开发空间,替换系统通⽤下的对应⽂件.
catkin⽀持包的逐层覆盖, 当前最⾼,其它依据source的顺序逐层变⾼, ⾼层可覆盖低层.
Example 4: Overlaying workspace 3 on top of local workspace2 install space on top of workspace1 devel space on top of system install
cd ~/workspace2/build
cmake -DCMAKE_INSTALL_PREFIX=~/ws2_installed ../src
make
make install
source ~/ws2_installed/tup.bash
cd ~/workspace3/build
cmake ../src
make
ros 环境变量设置可以参考
#package slam_ws
source /opt/ros/indigo/tup.bash
source /home/yhzhao/slam_ws/devel/tup.bash
export ROS_PACKAGE_PATH=~/slam_ws/src:$ROS_PACKAGE_PATH
export ROS_WORKSPACE=~/slam_ws/src
混合 Mixing catkin And rosbuild Workspaces
catkin was designed to allow rosbuild packages to sit on top of catkin ones. This is accomplished by using overlays
~/rosbuild_ws/
dry_pkg1/
...
dry_pkgN/
tup.bash
tup.sh
~/catkin_ws/
src/
wet_pkg1/
...
预备党员的思想汇报
wet_pkgN/
build/
devel/
tup.bash
tup.sh
install/
tup.bash
tup.sh
注: 我们在系统⽂件夹下的 .bashrc 中加⼊相应的source⽂件, 就是为了添加ros 的环境变量等信息.
catkin_make 编译指定的包.
$ catkin_make -DCATKIN_WHITELIST_PACKAGES="package1;package2"
恢复编译所有的包
$ catkin_make -DCATKIN_WHITELIST_PACKAGES=""
3
4 与 CMakeList. txt
4.1
每个包的描述⽂件,都需要放置在包的根⽬录下,对包的名字/版本/作者/维护者/依赖关系进⾏说明.与rosbuild中的l相似. 依赖不正确在本地可以可以编译通过,但不能在ROS社区正确⼯作起来.
4.1.1 格式
<package>
<name>foo_core</name>
<version>1.2.4</version>
<description>
This package provides foo capability.
</description>
<maintainer email="">Ivana Bildbotz</maintainer>
<licen>BSD</licen>
<url>ros/wiki/foo_core</url>
<author>Ivana Bildbotz</author>
<buildtool_depend>catkin</buildtool_depend>
<depend>roscpp</depend>
<depend>std_msgs</depend>
<build_depend>message_generation</build_depend>
<exec_depend>message_runtime</exec_depend>
<exec_depend>rospy</exec_depend>
<test_depend>python-mock</test_depend>
<doc_depend>doxygen</doc_depend>
</package>
干蒸和湿蒸的区别
6种依赖标签
Build Dependencies #包编译需要依赖的包.
Build Export Dependencies #指出你的包编译导出库 (): b依赖a的头⽂件,要想c只依赖b.我认为是避免多次依赖.
specify which packages are needed to build libraries against this package. This is the ca when you transitively include their headers in public headers in this package (especially when the packages are declared as (CATKIN_)DEPENDS in catkin_package() in CMake).
Execution Dependencies #执⾏时依赖
Test Dependencies #单元测试
Build Tool Dependencies #编译系统⼯具
Documentation Tool Dependencies #doc⽣成⼯具
<depend> specifies that a dependency is a build, export, and execution dependency. This is the most commonly ud dependency tag.
<buildtool_depend>
<build_depend>
<build_export_depend>
<exec_depend>
<test_depend>
<doc_depend>write.blog.csdn/postedit/50388429
4.1.2 Metapackages 将多个包组合成⼀个逻辑包
<export>
<metapackage />
</export>
仅需要标签: <buildtool_depends> 依赖 catkin 和 <run_depend>
对应中
cmake_minimum_required(VERSION 2.8.3)
project(<PACKAGE_NAME>)
find_package(catkin REQUIRED)
卜算子咏梅拼音版catkin_metapackage()
例如 universal_robot的l
<package>
<name>universal_robot</name>
<version>1.1.5</version>
<description>
Drivers, description, and utilities for Universal Robot Arms.
</description>
<maintainer email="aub@ipa.fhg.de">Alexander Bubeck</maintainer>
<licen>BSD</licen>
<url type="website">ros/wiki/universal_robot</url>
<author email="dwards@swri">Shaun Edwards</author>
<author>Stuart Glar</author>
<author email="kphawkins@gatech.edu">Kely Hawkins</author>
<author>Wim Meeusn</author>
<author email="fxm@ipa.fhg.de">Felix Messmer</author>
七夕网
<buildtool_depend>catkin</buildtool_depend>
我爱米奇<run_depend>ur3_moveit_config</run_depend>
<run_depend>ur5_moveit_config</run_depend>
<run_depend>ur10_moveit_config</run_depend>
<run_depend>ur_bringup</run_depend>
<run_depend>ur_description</run_depend>
<run_depend>ur_driver</run_depend>
<run_depend>ur_gazebo</run_depend>
<run_depend>ur_kinematics</run_depend>
<run_depend>ur_msgs</run_depend>
<export>
<metapackage/>
</export>
</package>
cmake_minimum_required(VERSION 2.8.3)
project(universal_robot)
find_package(catkin REQUIRED)
catkin_metapackage()
4.2 cmak 不会找l⽂件, 但catkin需要. 依据⽂件编译需要清晰指出头⽂件和库⽂件的指向. Finding the library
find_package(catkin REQUIRED COMPONENTS roscpp)
Include directories
include_directories(include ${catkin_INCLUDE_DIRS})
Exporting interfaces
需要在l中使⽤<depend>或者<build_export_depend>,catkin_package() 命令仅调⽤⼀次,它需要额外的参数依赖于你的包导出的依赖.
catkin_package(CATKIN_DEPENDS angles roscpp std_msgs)
4.3 C++ 系统库依赖
Finding the library
4.3.1 依据CMake module . ⼤部分的boost 库在头⽂件完全实现,运⾏时不需要独⽴的分享连接
find_package(Boost REQUIRED)
但boost thread 运⾏时需要库,必须指出组件thread .
find_package(Boost REQUIRED COMPONENTS thread)
find_package()之后就可以⽤此编译和连接了. 命名规则基本是这样: ${name}_INCLUDE_DIRS and${name}_LIBRARIES .有时不遵循
4.3.2 cmake modules ⽆效情况下,但库开发包提供了pkg-config module . 编译标签
find_package(PkgConfig REQUIRED)
pkg_check_modules(GSTREAMER REQUIRED libgstreamer-0.10)
pkg_check_modules() 参数声明了⼀个cmake前缀,GSTREAMER_INCLUDE_DIRS 和GSTREAMER_LIBRARIES
PkgConfig 编译应⽤与连接的帮助⼯具. ⽤于命令⾏中插⼊正确的编译选项. (.pc⽂件 ) libgstreamer-0.10.pc.
Include directories
include_directories(include ${Boost_INCLUDE_DIRS} ${GSTREAMER_INCLUDE_DIRS})
如有依赖catkin 包 ,再添加${catkin_INCLUDE_DIRS}
Exporting interfaces
catkin_package(DEPENDS Boost GSTREAMER)
确保所有的包在l被⽤到,<build_export_depend>和<depend>标签.
丰收季节标准命名 ${name}_INCLUDE_DIRS and${name}_LIBRARIES . catkin包⼀般是⼩写,⼤写(asGSTREAMER) 或混合 (likeBoost)
4.4 编译安装 C++ libraries and headers
include_directories(include
${catkin_INCLUDE_DIRS}
${Boost_INCLUDE_DIRS}
${GSTREAMER_INCLUDE_DIRS})
add_library(your_library libsrc1.cpp libsrc2.cpp libsrc_etc.cpp)
t(YOUR_LIB_SOURCES
libsrc1.cpp
libsrc2.cpp
libsrc3.cpp
libsrc4.cpp
libsrc_etc.cpp)
add_library(your_library ${YOUR_LIB_SOURCES})
target_link_libraries(your_library ${catkin_LIBRARIES})
target_link_libraries(your_library
${catkin_LIBRARIES}
${Boost_LIBRARIES}
${GSTREAMER_LIBRARIES})
catkin_package(CATKIN_DEPENDS std_msgs
DEPENDS Boost
INCLUDE_DIRS include
LIBRARIES your_library)
<depend>std_msgs</depend>
<build_export_depend>boost</build_export_depend>
安装
install(TARGETS your_library your_other_library
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION}) install(DIRECTORY include/${PROJECT_NAME}/
DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION})
install(DIRECTORY include/${PROJECT_NAME}/
DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
PATTERN ".svn" EXCLUDE)
4.5 编译安装 C++ 执⾏⽂件
include_directories(include
${catkin_INCLUDE_DIRS}
${Boost_INCLUDE_DIRS}
${GSTREAMER_INCLUDE_DIRS})
add_executable(your_node src1.cpp src2.cpp src_etc.cpp)
t(${PROJECT_NAME}_SOURCES
src/file1.cpp
src/file2.cpp
src/file3.cpp
src/file4.cpp
src/file5.cpp
src/file6.cpp
src/file_etc.cpp)
add_executable(your_node ${${PROJECT_NAME}_SOURCES})
add_executable(your_node ${${PROJECT_NAME}_SOURCES})
target_link_libraries(your_node ${catkin_LIBRARIES})
add_executable(your_node ${${PROJECT_NAME}_SOURCES})
target_link_libraries(your_node
${catkin_LIBRARIES}
${Boost_LIBRARIES}
${GSTREAMER_LIBRARIES})
ros下的安装,使得rosrun 与roslaunch能够使⽤.需要下⾯的⽅式安装install(TARGETS your_node
RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION})
安装 cmake⽂件
catkin_package(CFG_EXTRAS ake ake) install(FILES cmake/ake cmake/ake
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}/cmake) install(DIRECTORY cmake
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
PATTERN ".svn" EXCLUDE)
参考: