QT Cmake添加srv和msg
1 CmakeLists.txt
cmake_minimum_required(VERSION 2.8.3) project(map_msgs) find_package(catkin REQUIRED COMPONENTS std_msgs sensor_msgs nav_msgs message_generation ) add_message_files( FILES NaviStatusCode.msg NaviStatusResponse.msg ) add_service_files( FILES String.srv NaviStatusSwitch.srv ) generate_messages( DEPENDENCIES std_msgs sensor_msgs nav_msgs ) catkin_package( CATKIN_DEPENDS std_msgs message_runtime sensor_msgs nav_msgs ) install( DIRECTORY include/${PROJECT_NAME}/ DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION} FILES_MATCHING PATTERN "*.h" )
2 package.xml
<package> <name>map_msgs</name> <version>1.13.0</version> <description> This package defines messages commonly used in mapping packages</description> <author>Unknow</author> <maintainer email="Unknow@126.com">Unknow</maintainer> <license>Unknow</license> <buildtool_depend>catkin</buildtool_depend> <build_depend>message_generation</build_depend> <build_depend>std_msgs</build_depend> <build_depend>sensor_msgs</build_depend> <build_depend>nav_msgs</build_depend> <run_depend>message_runtime</run_depend> <run_depend>std_msgs</run_depend> <run_depend>sensor_msgs</run_depend> <run_depend>nav_msgs</run_depend> </package>
3链接常见错误
如果在工程中添加消息或者服务,头文件依赖其生成的头文件,直接编译会报错,必须在CmakeLists.txt中添加以下依赖 generate_messages_cpp,生成可执行程序之前首先编译生成消息头文件
add_dependencies(${PROJECT_NAME}
${catkin_EXPORTED_TARGETS}
${PROJECT_NAME}_generate_messages_cpp
)