ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

How to include header file generated by catkin srv?

asked 2014-07-09 03:31:50 -0500

sam gravatar image

The error is:

/home/ira/code/ros_groovy/src/sam_semantic_map_builder_dir/src/sam_semantic_map_builder_src.cpp:2:55: fatal error: sam_semantic_map_builder_dir/srv_add_file.h: No such file or directory
compilation terminated.

I run:

catkin_create_pkg sam_semantic_map_builder_dir pcl pcl_ros roscpp sensor_msgs
roscd sam_semantic_map_builder_dir
mkdir -p srv

vim srv/srv_add_file.srv

string msg_object_name
float32 msg_x
float32 msg_y
float32 msg_z
float32 msg_roll
float32 msg_pitch
float32 msg_yaw

vim src/sam_semantic_map_builder_src.cpp

#include <ros/ros.h>
#include <sam_semantic_map_builder_dir/srv_add_file.h>

vim CMakeLists.txt

cmake_minimum_required(VERSION 2.8.3)
find_package(catkin REQUIRED COMPONENTS
## Generate services in the 'srv' folder
  INCLUDE_DIRS include
#  LIBRARIES sam_semantic_map_builder_dir
  CATKIN_DEPENDS pcl pcl_ros roscpp sensor_msgs
  #  DEPENDS system_lib
# include_directories(include)
add_executable(sam_semantic_map_builder_bin src/sam_semantic_map_builder_src.cpp)
target_link_libraries(sam_semantic_map_builder_bin ${catkin_LIBRARIES})

vim package.xml

<?xml version="1.0"?>
  <description>The sam_semantic_map_builder_dir package</description>

  <!-- One maintainer tag required, multiple allowed, one person per tag --> 
  <!-- Example:  -->
  <!-- <maintainer email="">Jane Doe</maintainer> -->
  <maintainer email="ira@todo.todo">ira</maintainer>

  <!-- One license tag required, multiple allowed, one license per tag -->
  <!-- Commonly used license strings: -->
  <!--   BSD, MIT, Boost Software License, GPLv2, GPLv3, LGPLv2.1, LGPLv3 -->

  <!-- The export tag contains other, unspecified, tags -->
    <!-- You can specify that this package is a metapackage here: -->
    <!-- <metapackage/> -->

    <!-- Other tools can request additional information be placed here -->


What am I missing?

How to fix it?

Thank you~

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2014-07-09 04:08:16 -0500

Wolf gravatar image

You are missing 2 things:

1) In addition to add_service_files you need to call generate_messages (Typically just decomment this in the default generated CMakeLists.txt):

## Generate added messages and services with any dependencies listed here
  std_msgs  # and/or other packages containing depended messages

If you added this your code will compile 'most of the times'. However, the srv headers need to be compiled before your exec target and the order of command evaluation is not yet fixed. In order to fix the order you add:


add_dependencies( sam_semantic_map_builder_bin ${PROJECT_NAME}_generate_messages_cpp )

after add_executable. This makes your exec depending on the <>generate_messages_cpp thereby only allowing the exec target to be compiled after the msg headers are generated............

edit flag offensive delete link more

answered 2014-07-09 03:54:31 -0500

gvdhoorn gravatar image

A quick search leads to this answer by WilliamWoodall in How to specify dependencies with "foo_msgs" catkin packages.

See also C++ message or service dependencies on the excellent How to do common tasks page (you're most likely using package format 1).

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2014-07-09 03:31:50 -0500

Seen: 6,400 times

Last updated: Jul 09 '14