码迷,mamicode.com
首页 > 其他好文 > 详细

catkin_make 浅析

时间:2017-09-27 16:19:49      阅读:493      评论:0      收藏:0      [点我收藏+]

标签:/tmp   find   nes   amp   exe   shell   流程   ignore   ++   

引用自http://blog.csdn.net/zyh821351004/article/details/50388429

 

update:   catkin_tools

---------------------------------

Catkin Command Line Tools:   

Installing catkin_tools:      sudo apt-get install python-catkin-tools

---------------------------------

1.  catkin_make 与cmake的关系

    程序在cmake编译是这样的流程, cmake指令依据你的CMakeLists.txt 文件,生成makefiles文件,make再依据此makefiles文件编译链接生成可执行文件.

catkin_make是将cmake与make的编译方式做了一个封装的指令工具, 规范了工作路径与生成文件路径.

1)  cmake标准流程 

 

[cpp] view plain copy
 
  1. # 在一个CMake项目里  
  2. $ mkdir build  
  3. $ cd build  
  4. $ cmake ..  
  5. $ make  
  6. $ make install  # (可选)  

 

 

2) catkin_make 的流程

 

[cpp] view plain copy
 
  1. # In a catkin workspace  
  2. $ catkin_make  
  3. $ catkin_make install  # (可选)  
  4.   
  5.   
  6. 如果源码不在默认工作空间,需要指定编译路径:  
  7.   
  8. # In a catkin workspace  
  9. $ catkin_make --source my_src  
  10. $ catkin_make install --source my_src  # (optionally)  

 

2 catkin_make

CMake coding standards

CMake Variables

1) catkin_make默认的路径信息

 

[cpp] view plain copy
 
  1. 在catkin_make运行后终端输出文件部分解析  
  2.   
  3. #基本路径  
  4. Base path: /home/user/catkin_ws  
  5. Source space: /home/user/catkin_ws/src  
  6. Build space: /home/user/catkin_ws/build  
  7. Devel space: /home/user/catkin_ws/devel  
  8. Install space: /home/user/catkin_ws/install  
  9.   
  10.   
  11. #catkin_make 封装运行中cmake运行的情况  
  12. Running command: "cmake /home/user/catkin_ws/src -DCATKIN_DEVEL_PREFIX=/home/user/catkin_ws/devel   
  13. -DCMAKE_INSTALL_PREFIX=/home/user/catkin_ws/install" in "/home/user/catkin_ws/build"    
  14.   
  15. #编译工具查找  
  16. -- Using CATKIN_DEVEL_PREFIX: /tmp/catkin_ws/devel  
  17. -- Using CMAKE_PREFIX_PATH: /opt/ros/groovy  
  18. -- This workspace overlays: /opt/ros/groovy  
  19.   
  20. #编译的包  
  21. <pre name="code" class="cpp">#catkin_make 封装运行中make运行的情况  

#### Running command: "make -j4" in "/home/user/catkin_ws/build"


 


 

2)  layout :ros工作空间文件系统结构

 

[cpp] view plain copy
 
  1. workspace_folder/        --WORKSPACE  
  2.   src/                   --SOURCE SPACE  
  3.     CMakeLists.txt/      --This is symlinked to catkin/cmake/toplevel.cmake  
  4.     package_1/  
  5.       CMakeLists.txt  
  6.       package.xml  
  7.     ...  
  8.     package_n/  
  9.       CMakeLists.txt  
  10.       package.xml  
  11.   build/                 --BUILD SPACE(this is where build system is invoked, not necessarily within workspace)  
  12.     CATKIN_IGNORE        --Marking the folder to be ignored when crawling for packages (necessary when source   
  13.                             space is in the root of the workspace, the file is emtpy)  
  14.                             #此选项可用于忽略某个包编译  
  15.  devel/                 --DEVEL SPACE (targets go here, parameterizable, but defaults to peer of Build Space)  
  16.                            # 生成二值 库 可执行文件   
  17.     bin/  
  18.     etc/  
  19.     /include/  
  20.     lib/  
  21.     share/  
  22.     .catkin              --Marking the folder as a development space (the file contains a semicolon separated list of Source space paths)  
  23.                             #  
  24.     env.bash  
  25.     setup.bash  
  26.     setup.sh  
  27.     ...  
  28.   install/               --INSTALL SPACE (this is where installed targets for test installations go, not necessarily within workspace)  
  29.     bin/  
  30.     etc/  
  31.     include/  
  32.     lib/  
  33.     share/  
  34.     .catkin              --Marking the folder as an install space (the file is emtpy)  
  35.     env.bash  
  36.     setup.bash    -- Environment setup file for Bash shell  
  37.     setup.sh      -- Environment setup file for Bourne shell   
  38.     ...  
  39.   
  40.   
  41. /  
  42.   opt/  
  43.     ros/  
  44.       groovy/  
  45.         setup.bash -- Environment setup file for Bash shell  
  46.         setup.sh   -- Environment setup file for Bourne shell  
  47.         setup.zsh  -- Environment setup file for zshell  
  48.         ...  

工作空间

 

源空间

编译空间 

开发空间

安装空间  -DCMAKE_INSTALL_PREFIX=/any/directorycmake默认是/usr/local

系统安装空间         /opt/ros/ROSDISTRO

结果空间            source RESULT-SPACE/setup.sh             类似扫描安装空间与开发空间,替换系统通用下的对应文件.

 

3) Overlays

catkin支持覆盖.

catkin支持包的逐层覆盖, 当前最高,其它依据source的顺序逐层变高, 高层可覆盖低层.  

 

 

[cpp] view plain copy
 
  1. Example 4: Overlaying workspace 3 on top of local workspace2 install space on top of workspace1 devel space on top of system install  
  2.   
  3. cd ~/workspace2/build  
  4. cmake -DCMAKE_INSTALL_PREFIX=~/ws2_installed ../src  
  5. make  
  6. make install  
  7.   
  8. source ~/ws2_installed/setup.bash  
  9.   
  10. cd ~/workspace3/build  
  11. cmake ../src  
  12. make  

  

ros 环境变量设置 可以参考 .bashrc文件: ros工作环境设置

 

[cpp] view plain copy
 
  1. ######  slam_ws    
  2. source /opt/ros/indigo/setup.bash    
  3. source /home/yhzhao/slam_ws/devel/setup.bash    
  4.     
  5. export ROS_PACKAGE_PATH=~/slam_ws/src:$ROS_PACKAGE_PATH    
  6. export ROS_WORKSPACE=~/slam_ws/src    



 

 

4) 混合 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.

[cpp] view plain copy
 
  1. ~/rosbuild_ws/  
  2.    dry_pkg1/  
  3.    ...  
  4.    dry_pkgN/  
  5.    setup.bash  
  6.    setup.sh  
  7. ~/catkin_ws/  
  8.    src/  
  9.      wet_pkg1/  
  10.      ...  
  11.      wet_pkgN/  
  12.    build/  
  13.    devel/  
  14.      setup.bash  
  15.      setup.sh  
  16.    install/  
  17.      setup.bash   
  18.      setup.sh   

 

注:  我们在系统文件夹下的 .bashrc 中加入相应的source文件,  就是为了添加ros 的环境变量等信息.

Differences in CMakeLists.txt for rosbuild and catkin

 

5)  catkin_make 编译指定的包.

$ catkin_make -DCATKIN_WHITELIST_PACKAGES="package1;package2"

恢复编译所有的包

$ catkin_make -DCATKIN_WHITELIST_PACKAGES=""

 

3  catkin  

catkin/Tutorials

 

4.   package. xml  与  CMakeList. txt

4.1 package. xml 

catkin API docs.

每个包的描述文件,都需要放置在包的根目录下,对包的名字/版本/作者/维护者/依赖关系进行说明.与rosbuild中的manifest.xml相似.

依赖不正确在本地可以可以编译通过,但不能在ROS社区正确工作起来.

4.1.1  格式

 

[cpp] view plain copy
 
  1. <package>  
  2.   <name>foo_core</name>  
  3.   <version>1.2.4</version>  
  4.   <description>  
  5.     This package provides foo capability.  
  6.   </description>  
  7.   <maintainer email="ivana@willowgarage.com">Ivana Bildbotz</maintainer>  
  8.   <license>BSD</license>  
  9.   
  10.   <url>http://ros.org/wiki/foo_core</url>  
  11.   <author>Ivana Bildbotz</author>  
  12.   
  13.   <buildtool_depend>catkin</buildtool_depend>  
  14.   
  15.   <depend>roscpp</depend>  
  16.   <depend>std_msgs</depend>  
  17.   
  18.   <build_depend>message_generation</build_depend>  
  19.   
  20.   <exec_depend>message_runtime</exec_depend>  
  21.   <exec_depend>rospy</exec_depend>  
  22.   
  23.   <test_depend>python-mock</test_depend>  
  24.   
  25.   <doc_depend>doxygen</doc_depend>  
  26. </package>  


 

C++ catkin library dependencies

 

6种依赖标签

Build Dependencies     指出你的包编译需要依赖的包.

Build Export Dependencies      指出你的包编译导出库 (???):   b依赖a的头文件,要想c只依赖b.   我认为是避免多次依赖.

specify which packages are needed to build libraries against this package. This is the case when you transitively include their headers in public headers in this package (especially when these packages are declared as (CATKIN_)DEPENDS in catkin_package() in CMake).

Execution Dependencies   执行时依赖

Test Dependencies         单元测试

Build Tool Dependencies     编译系统工具

Documentation Tool Dependencies      doc生成工具

 

[cpp] view plain copy
 
  1. <depend> specifies that a dependency is a build, export, and execution dependency. This is the most commonly used dependency tag.  
  2. <buildtool_depend>  
  3. <build_depend>  
  4. <build_export_depend>  
  5. <exec_depend>  
  6. <test_depend>  
  7. <doc_depend>http://write.blog.csdn.net/postedit/50388429  
4.1.2 Metapackages   将多个包组合成一个逻辑包
[cpp] view plain copy
 
  1. <export>  
  2.   <metapackage />  
  3. </export>  

仅需要标签:   <buildtool_depends> 依赖 catkin   和  <run_depend>

 

对应cmakelists.txt中

 

[cpp] view plain copy
 
  1. cmake_minimum_required(VERSION 2.8.3)  
  2. project(<PACKAGE_NAME>)  
  3. find_package(catkin REQUIRED)  
  4. catkin_metapackage()  

 

========例如 universal_robot======================================

 

[cpp] view plain copy
 
  1. <package>  
  2.   <name>universal_robot</name>  
  3.   <version>1.1.5</version>  
  4.   <description>  
  5.       Drivers, description, and utilities for Universal Robot Arms.  
  6.   </description>  
  7.   
  8.   <maintainer email="aub@ipa.fhg.de">Alexander Bubeck</maintainer>  
  9.   
  10.   <license>BSD</license>  
  11.   
  12.   <url type="website">http://ros.org/wiki/universal_robot</url>  
  13.   
  14.   <author email="sedwards@swri.org">Shaun Edwards</author>  
  15.   <author>Stuart Glaser</author>  
  16.   <author email="kphawkins@gatech.edu">Kelsey Hawkins</author>  
  17.   <author>Wim Meeussen</author>  
  18.   <author email="fxm@ipa.fhg.de">Felix Messmer</author>  
  19.   
  20.   <buildtool_depend>catkin</buildtool_depend>  
  21.   <run_depend>ur3_moveit_config</run_depend>  
  22.   <run_depend>ur5_moveit_config</run_depend>  
  23.   <run_depend>ur10_moveit_config</run_depend>  
  24.   <run_depend>ur_bringup</run_depend>  
  25.   <run_depend>ur_description</run_depend>  
  26.   <run_depend>ur_driver</run_depend>  
  27.   <run_depend>ur_gazebo</run_depend>  
  28.   <run_depend>ur_kinematics</run_depend>  
  29.   <run_depend>ur_msgs</run_depend>  
  30.   
  31.   <export>  
  32.     <metapackage/>  
  33.   </export>  
  34. </package>  


 

 

[cpp] view plain copy
 
  1. cmake_minimum_required(VERSION 2.8.3)  
  2. project(universal_robot)  
  3. find_package(catkin REQUIRED)  
  4. catkin_metapackage()  


4.2  CMakeLists.txt

cmak 不会找package.xml文件, 但catkin需要.  依据cmakelists.txt文件编译需要清晰指出头文件和库文件的指向.  

 

Finding the library

 

需要在package.xml中使用标签<depend> 或者<build_depend>

find_package(catkin REQUIRED COMPONENTS roscpp)

 

Include directories

 

include_directories(include ${catkin_INCLUDE_DIRS})

 

Exporting interfaces

 

需要在package.xml中使用<depend> 或者<build_export_depend>,catkin_package() 命令仅调用一次,它需要额外的参数依赖

于你的包导出的依赖.

catkin_package(CATKIN_DEPENDS angles roscpp std_msgs)

 

4.3  C++ 系统库依赖

 

Finding the library  

 

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 .有时不遵循

 

camke社区标准命名的就请到到answers.ros.org发问.

 

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)

确保所有的包在package.xml被用到,  <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)
set(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)
set(${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 your_macros.cmake your_modules.cmake)
install(FILES cmake/your_macros.cmake cmake/your_modules.cmake
        DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}/cmake)
install(DIRECTORY cmake
        DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
        PATTERN ".svn" EXCLUDE)

 

 

 

4.6  CMake coding standards

4.7   CMake Variables

CMake Useful Variables


 

 

参考:

http://wiki.ros.org/catkin

http://wiki.ros.org/catkin/commands/catkin_make

http://wiki.ros.org/cn/ROS/Tutorials/catkin/BuildingPackages

 

CMake coding standards

CMake Variables

 

CMake Useful Variables

catkin_make 浅析

标签:/tmp   find   nes   amp   exe   shell   流程   ignore   ++   

原文地址:http://www.cnblogs.com/marty86/p/7601929.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!