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

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)
project(sam_semantic_map_builder_dir)
find_package(catkin REQUIRED COMPONENTS
  pcl
  pcl_ros
  roscpp
  sensor_msgs
  std_msgs
  message_generation
)
## Generate services in the 'srv' folder
 add_service_files(
   FILES
   srv_add_file.srv
 )
catkin_package(
  INCLUDE_DIRS include
#  LIBRARIES sam_semantic_map_builder_dir
  CATKIN_DEPENDS pcl pcl_ros roscpp sensor_msgs
  #  DEPENDS system_lib
)
# include_directories(include)
include_directories(
  ${catkin_INCLUDE_DIRS}
)
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"?>
<package>
  <name>sam_semantic_map_builder_dir</name>
  <version>0.0.0</version>
  <description>The sam_semantic_map_builder_dir package</description>

  <!-- One maintainer tag required, multiple allowed, one person per tag --> 
  <!-- Example:  -->
  <!-- <maintainer email="jane.doe@example.com">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 -->
  <license>TODO</license>
  <buildtool_depend>catkin</buildtool_depend>
  <build_depend>pcl</build_depend>
  <build_depend>pcl_ros</build_depend>
  <build_depend>roscpp</build_depend>
  <build_depend>sensor_msgs</build_depend>
  <build_depend>message_generation</build_depend>
  <run_depend>pcl</run_depend>
  <run_depend>pcl_ros</run_depend>
  <run_depend>roscpp</run_depend>
  <run_depend>sensor_msgs</run_depend>
  <run_depend>message_runtime</run_depend>


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

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

  </export>
</package>

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
3

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
generate_messages(
  DEPENDENCIES
  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:

2)

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
1

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

Stats

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

Seen: 6,402 times

Last updated: Jul 09 '14