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

Unable to get any msgs/srvs to work in CMakeLists [closed]

asked 2020-10-30 21:06:23 -0500

lutinplunder gravatar image

I am trying to build a controller node for a robot in ROS2 foxy and CMake is kicking my ass. When I try to add a library none of the msgs/srvs work either my custom one or a built in such as std_msgs

Here is the type of error I get from the console, it's pretty much the same for all the msgs/srvs:

colcon build --packages-select legged_robot_controller
Starting >>> legged_robot_controller
--- stderr: legged_robot_controller                             
In file included from /home/robdome/ros2_ws/src/legged_robot_controller/src/control.cpp:31:
/home/robdome/ros2_ws/src/legged_robot_controller/include/legged_robot_controller/control.hpp:38:10: fatal error: std_srvs/srv/Empty.hpp: No such file or directory
   38 | #include <std_srvs/srv/Empty.hpp>
      |          ^~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make[2]: *** [CMakeFiles/control.dir/build.make:63: CMakeFiles/control.dir/src/control.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:107: CMakeFiles/control.dir/all] Error 2
make: *** [Makefile:141: all] Error 2
Failed   <<< legged_robot_controller [5.58s, exited with code 2]

Summary: 0 packages finished [6.01s]
  1 package failed: legged_robot_controller
  1 package had stderr output: legged_robot_controller

Here is my CMakeLists:

find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(geometry_msgs REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(std_msgs REQUIRED)
find_package(std_srvs REQUIRED)
find_package(nav_msgs REQUIRED)
find_package(legged_robot_msgs REQUIRED)
find_package(tf2_ros REQUIRED)
find_package(dynamixel_sdk REQUIRED)

add_library( control src/control.cpp )
ament_target_dependencies( control


install(DIRECTORY include/${PROJECT_NAME}

ament_export_dependencies(rclcpp geometry_msgs sensor_msgs std_srvs std_msgs legged_robot_msgs 



I've spent that last day or so trying to figure it out on my own to no avail, I apologize if I'm doing something stupid I'm new to ROS and don't have a whole lot of C++ experience.

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by lutinplunder
close date 2020-11-05 20:22:16.137883

2 Answers

Sort by ยป oldest newest most voted

answered 2020-11-01 12:58:13 -0500

jschornak gravatar image

In ROS2's rclcpp, the names of the header files for message, service, and action definitions are lowercase separated by underscores. For Empty.srv, try including it using:

#include <std_srvs/srv/empty.hpp>
edit flag offensive delete link more


thanks schornak, that did it now I just need to figure out why my custom msgs aren't generating a .hpp EDIT: they are being generated I'm guessing I need to point CMake to the install folder?

lutinplunder gravatar image lutinplunder  ( 2020-11-01 22:10:30 -0500 )edit

I'd suggest posting a new question with some details (CMakeLists.txt, etc.) about the package where your custom msgs are defined and generated.

jschornak gravatar image jschornak  ( 2020-11-02 09:02:27 -0500 )edit

I figured it out, my cmake was fine my includes were pointing to the actual msg name not the name of the generated .hpp. I figured I'd just add that here for continuity.

lutinplunder gravatar image lutinplunder  ( 2020-11-02 21:07:02 -0500 )edit

answered 2020-10-31 17:49:56 -0500

JackB gravatar image

updated 2020-10-31 17:51:02 -0500

I think your include statement should be #include <std_srvs/Empty.h>.

EDIT: But this is ROS1 and I guess ROS2 is different?

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2020-10-30 21:06:23 -0500

Seen: 537 times

Last updated: Nov 01 '20