• ros自定义消息包无法编译生成.h文件的问题解决


    ros自定义消息包无法编译生成.h文件的问题解决

    想要创建一个ROS功能包专门存放自己自定义的消息,想将这些消息都生成.h,可以由别的功能包来调用。
    但是参照网上的诸多帖子未能解决,例如
    https://blog.csdn.net/feidaji/article/details/103601529
    https://blog.csdn.net/blue_skyLZW/article/details/112572226
    https://blog.csdn.net/zhou2677273778/article/details/126477921

    建立工作空间

    mkdir -p catkin_ws/src
    cd catkin_ws/src
    catkin_init_workspace
    cd ..
    catkin_make
    
    • 1
    • 2
    • 3
    • 4
    • 5

    创建功能包

    cd src
    catkin_create_pkg testmsg roscpp rospy std_message message_generation
    cd testmsg
    mkdir msg
    cd msg
    touch test1.msg //创建一个自定义消息
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    在CmakeList里面,要加上这些

    find_package(catkin REQUIRED COMPONENTS
      message_generation
      roscpp
      rospy
      std_msgs
    
     add_message_files(
       FILES
       test1.msg
    #   Message2.msg
     )
      generate_messages(
       DEPENDENCIES
       std_msgs
     )
    catkin_package(
    #  INCLUDE_DIRS include
    #  LIBRARIES test_msg
      CATKIN_DEPENDS message_generation roscpp rospy std_msgs
    #  DEPENDS system_lib
    )
    include_directories(
    # include
      ${catkin_INCLUDE_DIRS}
    )
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25

    按理说这样已经可以直接编译了,因为把消息也加入了CmakeList,但是编译的结果是这样的
    在这里插入图片描述
    或者这样的
    在这里插入图片描述
    其主要原因是由catkin_create_pkg testmsg roscpp rospy std_message message_generation这个自动生成的
    package.xml有问题

     <buildtool_depend>catkin</buildtool_depend>
    
      <build_depend>roscpp</build_depend>
      <build_depend>rospy</build_depend>
      <build_depend>std_msgs</build_depend>
    
      <build_export_depend>roscpp</build_export_depend>
      <build_export_depend>rospy</build_export_depend>
      <build_export_depend>std_msgs</build_export_depend>
    
      <exec_depend>roscpp</exec_depend>
      <exec_depend>rospy</exec_depend>
      <exec_depend>std_msgs</exec_depend>
      <exec_depend>message_generation</exec_depend>
      <exec_depend>message_runtime</exec_depend>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15

    将message_generation,message_runtime与其他库保持一致

     <buildtool_depend>catkin</buildtool_depend>
    
      <build_depend>roscpp</build_depend>
      <build_depend>rospy</build_depend>
      <build_depend>std_msgs</build_depend>
      <build_depend>message_generation</build_depend>
       <build_depend>message_runtime</build_depend>
    
      <build_export_depend>roscpp</build_export_depend>
      <build_export_depend>rospy</build_export_depend>
      <build_export_depend>std_msgs</build_export_depend>
      <build_export_depend>message_generation</build_export_depend>
      <build_export_depend>message_runtime</build_export_depend>
    
      <exec_depend>roscpp</exec_depend>
      <exec_depend>rospy</exec_depend>
      <exec_depend>std_msgs</exec_depend>
      <exec_depend>message_generation</exec_depend>
      <exec_depend>message_runtime</exec_depend>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19

    发现可以编译成功,devel/include/testmsg里面也有testmsg.h文件

  • 相关阅读:
    抢票攻略来了!疫情后的首届云栖大会
    使用HTML制作静态网站:传统文化戏剧锡剧带psd设计图(2个页面)
    ubuntu安装配置svn
    k8s驱逐(3)-kubelet节点压力驱逐-源码分析篇
    2022年全球市场RNA靶向小分子药物总体规模、主要企业、主要地区、产品和应用细分研究报告
    基于C语言实现了PASCAL编译器
    Toaster - Android 吐司框架,专治 Toast 各种疑难杂症
    MINA架构DEMO
    《XSS-Labs》02. Level 11~20
    docker install consul
  • 原文地址:https://blog.csdn.net/weixin_43658047/article/details/134322120