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
创建功能包
cd src
catkin_create_pkg testmsg roscpp rospy std_message message_generation
cd testmsg
mkdir msg
cd msg
touch test1.msg //创建一个自定义消息
在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}
)
按理说这样已经可以直接编译了,因为把消息也加入了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>
将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>
发现可以编译成功,devel/include/testmsg里面也有testmsg.h文件