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

How is the service.hpp file generated from service.srv file in ROS2 ?

asked 2018-05-15 12:30:00 -0600

aks gravatar image

updated 2018-05-16 06:12:39 -0600

While using services in ROS2, we include example_interfaces/srv/add_two_ints.hpp in the server.cpp and client.cpp files. How is this file generated.

In my case, i created a new service file heatFlow.srv and changed the CMakeLists.txt file and the cpp files accordingly. But when i try to build the package, it gives a fatal error : fatal error: example_interfaces/srv/heatFlow.hpp: No such file or directory compilation terminated.

How are these .hpp files basically generated ?


I created a new folder "example_interface" (note: without S in the end) and created a new service file called heatFlow.srv. Now the CMakeLists is as follows :

cmake_minimum_required(VERSION 3.5)
# Default to C++14
# we dont use add_compile_options with pedantic in message packages
# because the Python C extensions dont comply with it
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic")
find_package(ament_cmake REQUIRED)
find_package(rosidl_default_generators REQUIRED)
install(FILES mapping_rules.yaml DESTINATION share/${PROJECT_NAME})

and the package.xml as follows:

 > <?xml version="1.0"?>
 <?xml-model href="" schematypens="    /2001/XMLSchema"?>
 <package format="3">
 <description>Contains message and service definitions used by the examples.</description>
 <maintainer email="">Dirk Thomas</maintainer>
 <license>Apache License 2.0</license>
 <ros1_bridge mapping_rules="mapping_rules.yaml"/>

When I compile it using : ament build --symlink-install --only-package heatflow_cpp, it gives an error `CMake Error at CMakeLists.txt:15 (find_package): By not providing "Findexample_interface.cmake" in CMAKE_MODULE_PATH this project has asked CMake to find a package configuration file provided by "example_interface", but CMake did not find one.

Could not find a package configuration file provided by "example_interface" with any of the following names:


Add the installation prefix of "example_interface" to CMAKE_PREFIX_PATH or set "example_interface_DIR" to a directory containing one of the above files. If "example_interface" provides a separate development package or SDK, be sure it has been installed.`

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2018-05-16 04:11:23 -0600


Can you give the CmakeFile/Package.xml you created for your service? In my case it looks like

If the service name is 'aes_custom_interface' Then you need to add the following line in the package,xml that is using this specific service;


And in the Cmake:

find_package(aes_custom_interface REQUIRED)

About the generation of those header file, I believe this is done in _rosidl_generate_interfaces_ function which is then generating header files for ROS2 and IDL files for the DDS.

Hope it helps!

edit flag offensive delete link more


@pokitoz thanks for the suggestion but i guess i have already added the dependencies. I have edited the question with the CMakelists and package.xml

aks gravatar image aks  ( 2018-05-16 05:01:56 -0600 )edit

I would suggest to build from start (remove the --only-package heatflow_cpp). I think you are trying to build the package heatflow_cpp. I don't think the dependencies are build using --only-package.

Probably the package 'example_interface' containing your service has never been build.

pokitoz gravatar image pokitoz  ( 2018-05-16 06:22:59 -0600 )edit

yes, think this could be the point. But when i try to build all i get an error rosidl_parser.InvalidResourceName: heatFlow_Request CMakeFiles/example_interfaces__cpp.dir/build.make:90: recipe for target 'rosidl_generator_cpp/example_interfaces/srv/add_two_ints.hpp' failed. I replaced the...

aks gravatar image aks  ( 2018-05-16 10:25:28 -0600 )edit

AddTwoInts_Request with heatFlow_Request in the add_two_ints_client.cpp

aks gravatar image aks  ( 2018-05-16 10:26:43 -0600 )edit

I have the same error. However, i do can compile my pkg with the srv, but the code pkg doesnt find the service. Dont know what to do. I will appreciate the help, thank you.

Peanpepu gravatar image Peanpepu  ( 2022-04-26 01:43:08 -0600 )edit

Question Tools



Asked: 2018-05-15 12:30:00 -0600

Seen: 1,198 times

Last updated: May 16 '18