首先在CMakeLists.txt,在find_package 中添加 message_generation
find_package(catkin REQUIRED COMPONENTS
rviz
std_msgs
geometry_msgs
message_generation
)
add_message_files(
FILES
MoveToGrabMsg.msg
LoopMoveToGrabMsg.msg
)
generate_messages(
DEPENDENCIES std_msgs geometry_msgs
)
编译库和可执行文件时要添加add_dependencies
add_library(${PROJECT_NAME} ${SRC_FILES})
add_dependencies(${PROJECT_NAME} ${${PROJECT_NAME}_EXPORTTED_TARGETS} ${catkin_EXPORTED_TARGETS} ${PROJECT_NAME}_generate_messages_cpp)
add_executable(excute_navigation src/excute_navigation.cpp)
add_dependencies(excute_navigation ${${PROJECT_NAME}_EXPORTTED_TARGETS}
${catkin_EXPORTED_TARGETS}
${PROJECT_NAME}_generate_messages_cpp
${PROJECT_NAME}_gencpp
)
target_link_libraries(excute_navigation ${catkin_LIBRARIES})
在package.xml 中
<build_depend>message_generation</build_depend>\
<build_depend>message_runtime</build_depend>
<build_export_depend>message_generation</build_export_depend>
<build_export_depend>message_runtime</build_export_depend>
<exec_depend>message_generation</exec_depend>
<exec_depend>message_runtime</exec_depend>