ROS 的Catkin_make ⽅式编译的( )
catkin_make 如何编译整个⼯作空间的软件包呢?
<,⼤家应该⽐较熟悉了,就是我们借助Cmake⾃动帮我们按照规则⽣成的makefile⽂件,来完成⼯程的编译、链接⼯作.
catkin_make是将cmake与make的编译⽅式做了⼀个封装的指令⼯具, 规范了⼯作路径与⽣成⽂件路径,⽽且在新建个⼯作空间时就帮我们创建了⼀个顶层的⽂件,它会递归的寻到当前⼯作空间下的所有软件包内的依次来编译每⼀个软件包。(src的每个包⾥都有的)
这就是为什么catkin_make命令在 ror_ws的⼯作空间⽬录下,src⽬录之上执⾏
ROS下的CmakeList基本与之前的⼀致,仅仅添加了⼀些ROS相关的内容如何查链接库find_package(PkgConfig)
pkg_check_modules
他们的语法规则find_package( <name>[version] [EXACT] [QUIET] [NO_MODULE] [ [ REQUIRED | COMPONENTS ] [componets… ] ] )
name 和version是库的名称和版本
后⾯的参数
EXACT 要求版本号必须精确匹配
QUIET 没有到也不会有警告信息,会禁掉包没有被发现时的警告信息
REQUIRED 如果报没有到的话,cmake的过程会终⽌,并输出警告信息(说明这个module是⼯程必须有的)
COMPONENTS COMPONENTS选项之后,可以列出⼀些与包相关(依赖)的部件清单(components list)例如
system的头文件find_package(PkgConfig) #查PkgConfig所指向库⽂件和头⽂件
find_package(catkin REQUIRED
COMPONENTS roscpp image_transport sensor_msgs nodelet
camera_calibration_parsers camera_info_manager
)pkg_check_modules(<PREFIX>[QUIET] [REQUIRED] <MODULE> )
检测所有给出的modules
PREFIX ⾃定义的前缀,查到之后,可以⽤这个前缀来代表相应的module
QUIET/ REQUIRED 和前⾯的类似
QUIET/ REQUIRED的区别,
如果没到,⼀个不会报错,接着继续进⾏,⼀个会警告,并终⽌Cmake 如果的话,⽆论是哪⼀种模式,都可以使⽤下⾯这些变量
#最顶端
cmake_minimum_required(VERSION 2.8.3)
project(gscam) //表⽰当前软件包的名称
<NAME>_FOUND
<NAME>_INCLUDE_DIRS or <NAME>_INCLUDES //头⽂件
<NAME>_LIBRARIES or <NAME>_LIBRARIES or <NAME>_LIBS //库⽂件
<NAME>_DEFINITIONS
看⼀个⽐较典型的例⼦
实现的功能就是在ROS⼯程中,使⽤gstreamer库
⾸先考虑gstreamer-1.0,其次考虑gstreamer-0.10,如果都没有,Cmake就进⾏不下去,
⽆论有哪⼀个下⾯的
后⾯的
catkin_package 可以DEPENDS GSTREAMER GST_APP
include_directories 可以包含 ${GST_APP_INCLUDE_DIRS}
add_library 可以包含 ${GSTREAMER_LIBRARIES} ${GST_APP_LIBRARIES}
# System Dependencies
find_package(PkgConfig) #查PkgConfig所指向库⽂件和头⽂件
#通过PkgConfig的环境变量下配置的 ××.pc 管理了很多软件的库⽂件和头⽂件
pkg_check_modules(GSTREAMER QUIET gstreamer-0.10)
# 查gstreamer-0.10模组 ,并且⾃定义前缀GSTREAMER
if(NOT GSTREAMER_FOUND)
#如果的了,当然可以使⽤GSTREAMER_FOUND,甚⾄后⾯的_INCLUDE_DIRS, 没到当然就是 NOT GSTREAMER_FOUND
set(GSTREAMER_VERSION_1_x TRUE) #设置⼀个变量GSTREAMER_VERSION_1_x = 1
endif()
if(GSTREAMER_VERSION_1_x) #GSTREAMER_VERSION_1_x为真,说明没有gstreamer-0.10
message(STATUS "gst 1.0") #暂且先把消息类型为STATUS类型的消息设置为 "gst 1.0"
pkg_check_modules(GSTREAMER REQUIRED gstreamer-1.0)
pkg_check_modules(GST_APP REQUIRED gstreamer-app-1.0)
#再查⼀下gstreamer-1.0,gstreamer-app-1.0 这回查的条件是REQUIRED的
else() #GSTREAMER_VERSION_1_x为假,说明有gstreamer-0.10
message(STATUS "gst 0.1")
pkg_check_modules(GSTREAMER REQUIRED gstreamer-0.10)
pkg_check_modules(GST_APP REQUIRED gstreamer-app-0.10)
#再查⼀下gstreamer-0.10,gstreamer-app-0.10 这回查的条件是REQUIRED的
endif()
添加依赖库
find_package
catkin_package
The find_package command is common cmake and is needed to load the catkin macros and specify dependencies to other ROS packages.
find_package(catkin REQUIRED
COMPONENTS roscpp image_transport sensor_msgs nodelet
camera_calibration_parsers camera_info_manager
)
>>>>>>>
## catkin specific configuration ##
>>>>>>>
## The catkin_package macro generates cmake config files for your package
## Declare things to be passed to dependent projects
## INCLUDE_DIRS: uncomment this if your package contains header files
## LIBRARIES: libraries you create in this project that dependent projects also need
## CATKIN_DEPENDS: catkin_packages dependent projects also need
## DEPENDS: system dependencies of this project that dependent projects also need
catkin_package(
# INCLUDE_DIRS include
# LIBRARIES gstcamera
# CATKIN_DEPENDS other_catkin_pkg
# DEPENDS system_lib
)
catkin_package(
INCLUDE_DIRS include
LIBRARIES gscam
CATKIN_DEPENDS roscpp nodelet image_transport sensor_msgs
camera_calibration_parsers camera_info_manager
DEPENDS GSTREAMER GST_APP
)
catkin_package的⼀些参数
macro defined in ake
Parameters
INCLUDE_DIRS 当前⼯程下的include
– CMAKE_CURRENT_SOURCE_DIR-relative paths to C/C++ includes
LIBRARIES 和find_package同样的 ros内部依赖的库
– names of library targets that will appear in the catkin_LIBRARIES and ${PROJECT_NAME}_LIBRARIES of other projects that search for you via find_package. #CATKIN_DEPENDS – a list of catkin projects which this project depends on.
DEPENDS ⼯程依赖的外部库
– a list of CMake projects which this project depends on.
在⼯程中添加 头⽂件、库⽂件、可执⾏⽂件
头⽂件
include_directories(
include #当前⼯程下的include
${catkin_INCLUDE_DIRS}#<name_INCLUDE_DIRS>
${GLIB_INCLUDE_DIRS}
${GST_APP_INCLUDE_DIRS})
库⽂件
⼀般在add_library,add_executable之后
add_library(gscam src/gscam.cpp)
target_link_libraries(gscam
${catkin_LIBRARIES}
${GSTREAMER_LIBRARIES}
${GST_APP_LIBRARIES})
可执⾏⽂件
add_executable(gscam_node src/gscam_node.cpp)
target_link_libraries(gscam_node gscam
${catkin_LIBRARIES}
${GSTREAMER_LIBRARIES}
${GST_APP_LIBRARIES})
set_target_properties(gscam_node PROPERTIES OUTPUT_NAME gscam)
#变更target的属性 这⾥是改它的名字
Install
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
C语言基础-unlink函数的使用
« 上一篇
运动会分数统计系统课程设计报告
下一篇 »
发表评论