首页 > 编程语言 >ros2迁移c++之package.xml、CMakeLists.txt及编译

ros2迁移c++之package.xml、CMakeLists.txt及编译

时间:2023-09-14 17:48:12浏览次数:49  
标签:xml CMakeLists package DESTINATION library test dependencies ament ros2

1、package.xml

<package>               <!--1. 根标签-->
	<name>              <!--2. 包名-->
	<version>           <!--3. 版本号-->
	<description>       <!--4. 包描述-->
	<maintainer>        <!--5. 维护者-->
	<license>           <!--6. 软件许可-->
	<buildtool_depend>  <!--7. 编译构建工具,通常为catkin-->
	<depend>            <!--8. 指定依赖项为编译、 导出、 运行需要的依赖,最常用的依赖标记。-->
	<build_depend>      <!--9. 编译依赖项-->
	<build_export_depend> <!--10. 导出依赖项-->
	<exec_depend>         <!--11. 运行依赖项-->
	<test_depend>         <!--12. 测试用例依赖项-->
	<doc_depend>          <!--13. 文档依赖项-->
</package>                <!--根标签-->

ros2和ros1的基本通用,在ros2中由于编译模式的更改,需要删除catkin的相关内容,更改为ament_cmake

  <!-- ROS1 -->
  <buildtool_depend>catkin</buildtool_depend>
  <!-- The export tag contains other, unspecified, tags -->
  <export>
    <!-- Other tools can request additional information be placed here -->
  </export>
----------------------------------------------------------------------
  <!-- ROS2 -->
  <buildtool_depend>ament_cmake</buildtool_depend>
  <test_depend>ament_lint_auto</test_depend>
  <test_depend>ament_lint_common</test_depend>
  <export>
    <build_type>ament_cmake</build_type>
  </export>

2、CMakeLists.txt

2.1 find_package

# ros1
find_package(catkin REQUIRED COMPONENTS
  roscpp
  std_msgs
)
catkin_package(
  INCLUDE_DIRS include
  LIBRARIES test_library
  CATKIN_DEPENDS roscpp std_msgs
#  DEPENDS system_lib
)
----------------------------------------------------------------------
# ros2
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(std_msgs REQUIRED)
set(dependencies
  rclcpp
  std_msgs
)
# ament_target_dependencies是官方推荐的方式去添加依赖项。它将使依赖项的库、头文件和自身的依赖项被正常找到
ament_target_dependencies(
  ${dependencies}
)

2.2 include_directories

# ros1
include_directories(
  include
  ${catkin_INCLUDE_DIRS}
)
----------------------------------------------------------------------
# ros2
include_directories(
  include
)

2.3 动态库

# ros1
add_library(test_library
  src/test_library.cpp
)
add_dependencies(test_library ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
target_link_libraries(test_library
  ${catkin_LIBRARIES}
)
----------------------------------------------------------------------
# ros2
add_library(test_library SHARED
  src/test_library.cpp
)
# 通常来说,若依赖项为ROS2功能包时,则使用ament_target_dependencies。若功能包有多个库,它也将一并包含。
ament_target_dependencies(test_library 
  ${dependencies} # dependencies与前面提到的一致
)
# 链接自定义依赖库
target_link_libraries(test_library 
  lib1
)

2.4 可执行程序

# ros1
add_executable(test_node 
  src/main.cpp
)
add_dependencies(test_node ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
target_link_libraries(test_node 
    test_library 
    ${catkin_LIBRARIES}
)
----------------------------------------------------------------------
# ros2
add_executable(test_node 
	src/main.cpp
)
ament_target_dependencies(test_node 
  ${dependencies}
)
target_link_libraries(test_node 
	test_library 
)

2.5 install库及可执行文件

# ros1
# 安装库
install(TARGETS
  lib1
  lib2
  lib3
  ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
  LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
  RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION}
)
# 安装可执行文件
install(TARGETS
  node1
  node2
  node3
  RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)
# 安装头文件
install(DIRECTORY 
  include/${PROJECT_NAME}/
  DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
  FILES_MATCHING PATTERN "*.h"
  PATTERN ".svn" EXCLUDE
)
# 安装launch及其他文件
install(DIRECTORY launch
  DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
)
----------------------------------------------------------------------
# ros2---set方法在ros1中也可使用
# 安装库
set(librarys
  lib1 
  lib2 
  lib3 
)
install(TARGETS
  ${librarys}
  ARCHIVE DESTINATION lib
  LIBRARY DESTINATION lib
  RUNTIME DESTINATION bin
)
# 安装可执行文件
set(nodes
  node1 
  node2 
  node3 
)
install(TARGETS
  ${nodes}
  RUNTIME DESTINATION lib/${PROJECT_NAME}
)
# 安装头文件
install(DIRECTORY include/
  DESTINATION include/
)
# 安装launch及其他文件
install(DIRECTORY launch file
  DESTINATION share/${PROJECT_NAME}
)

2.6 标记头文件

# ros1
----------------------------------------------------------------------
# ros2
ament_export_include_directories(include)

2.7 供其他节点链接引用

# ros1
catkin_package(
  INCLUDE_DIRS include
  LIBRARIES lib1 lib2 lib3
  CATKIN_DEPENDS roscpp rospy std_msgs 
#  DEPENDS system_lib
)
----------------------------------------------------------------------
# ros2
set(librarys
  lib1 
  lib2 
  lib3 
)
# 其他的功能包能链接到这些库
ament_export_libraries(${librarys})
# ament_export_dependencies会将依赖项导出到下游软件包
ament_export_dependencies(${dependencies})

2.8 项目安装

# ros1
----------------------------------------------------------------------
# ros2--ament_package是CMakeLists.txt文件中的最后一个调用
ament_package()

3、编译

# ros1
# 编译整个工作空间
catkin_make -DCATKIN_WHITELIST_PACKAGES = ""
# 编译单独节点
catkin_make -DCATKIN_WHITELIST_PACKAGES = "pkg1"
----------------------------------------------------------------------
# ros2--colcon其余命令可自行查阅
# 编译整个工作空间
colcon build --symlink-install
# 编译单独节点
colcon build --packages-select pkg1

标签:xml,CMakeLists,package,DESTINATION,library,test,dependencies,ament,ros2
From: https://www.cnblogs.com/pptppa/p/17702815.html

相关文章

  • oracle获取xml节点数据
    1.新增获取节点函数CREATEORREPLACEFUNCTIONget_xml_nodeValue(xmlStrCLOB,nodeNameVARCHAR2)RETURNVARCHAR2ISxmlParxmlparser.Parser:=xmlparser.newParser;xDocxmldom.DOMDocument;lenItme......
  • java的配置类 取代xml配置文件
    配置类以及对注解@Value的使用//TODO:创建java的配置类取代xml配置文件@Configuration//配置类注解@ComponentScan({"com.wind.dao","com.wind.service"})//包扫描注解配置可存入多个包@PropertySource(value="classpath:jdbc.properties")//引用外部文件......
  • C# JSON字符串转带头(声明)XML字符串
     privatestringConverXml(stringmemberId,intcode,stringmsg)    {      varresp=new{authenticate=new{member_id=memberId,status_code=code,message=msg}};      varjsonstr=JsonConvert.SerializeObject(re......
  • Xstream操作xml_The type org.xmlpull.v1.XmlPullParser cannot be resolved. It is i
    //1.再使用xstream解析xml时发现总是报错Thetypeorg.xmlpull.v1.XmlPullParsercannotberesolved.Itisindirectlyreferencedfromrequired.classfiles//从bug中可以看出 XmlPullParser这个类为找打xstream需要依赖这个类从网上搜了一下这个类看看属于哪个jar包发现......
  • Error: Package: libselinux-python-2.2.2-6.el7.x86_64 (@anaconda) Requ
    ==========直接抛出问安装问题===场景安装nginx时相关的依赖包不配套问题 yum-yinstallgccpcre-develzlibzlib-developensslopenssl-devel ===系统centos7安装nginx====解决方案1.安装yum-utils相关工具yum-yinstallyum-utils2.清理yumyumcleanall3.清理未完成......
  • com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Java 8 date/time
    问题复现Java8date/timetypejava.time.LocalDateTimenotsupportedbydefault:addModule"com.fasterxml.jackson.datatype:jackson-datatype-jsr310"toenablehandling....在默认情况下Java8不支持LocalDateTime需要添加com.fasterxml.jackson.datatype:jackson-d......
  • Python3 XML 解析
    常见的XML编程接口有DOM和SAX,这两种接口处理XML文件的方式不同,当然使用场合也不同。Python有三种方法解析XML,SAX,DOM,以及ElementTree:1.SAX(simpleAPIforXML)Python标准库包含SAX解析器,SAX用事件驱动模型,通过在解析XML的过程中触发一个个的事件并调用用户......
  • opatch报补丁时,oui-patch.xml (Permission denied)报错
    前言一套19.19RAC环境,使用opatch工具安装数据库补丁,第一个节点成功安装,但在第二个节点执行opatch命令时报错。主要的错误有提示:/u01/app/oraInventory/ContentsXML/oui-patch.xml(Permissiondenied),具体如下所示。[grid@19crac235074478]$$ORACLE_HOME/OPatch/opatcha......
  • XMLHttpRequest xhr请求
    1.属性①readyState:xhr的状态码。②status:http状态码。③statusText:http状态说明文本。④response:响应。(可通过xhr.response获取响应体数据)⑤responseType:响应类型。⑥responseURL:响应的URL路径。⑦responseText:响应的文本数据。⑧responseXML:响应的XML数据。......
  • 解决IDEA不编译java目录下的xml文件
    对于IDEA系列编辑器,XML文件是不能放在java文件夹中的,IDEA默认不会编译源码文件夹中的XML文件,可以参照以下方式解决:<build><resources><resource><!--xml放在java目录下--><directory>src/main/java</directory><includes>......