在ROS 中新添加msg ,但在引用消息msg.h 时编译报错无法找到头文件

首先在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 中

  message_generation\
  message_runtime

  message_generation
  message_runtime

  message_generation
  message_runtime

 

你可能感兴趣的:(ros,ros消息头文件)