Cannot compile section 4.6

I was following the instructions for section 4.6: Custom service interface, and the following error popped up, it worked if I created a new package only for that service, is it possible the issue is with the package also has another custom interface: Age.msg?

user:~/ros2_ws$ colcon build --packages-select custom_interfaces
Starting >>> custom_interfaces
--- stderr: custom_interfaces
CMake Error at /opt/ros/foxy/share/rosidl_cmake/cmake/rosidl_generate_interfaces.cmake:213 (add_custom_target):
  add_custom_target cannot create target "custom_interfaces" because another
  target with the same name already exists.  The existing target is a custom
  target created in source directory
  "/home/user/ros2_ws/src/custom_interfaces".  See documentation for policy
  CMP0002 for more details.
Call Stack (most recent call first):
  CMakeLists.txt:41 (rosidl_generate_interfaces)


make: *** [Makefile:748: cmake_check_build_system] Error 1
---
Failed   <<< custom_interfaces [1.96s, exited with code 2]

Summary: 0 packages finished [2.17s]
  1 package failed: custom_interfaces
  1 package had stderr output: custom_interfaces

Hello @bd16 ,

The problem is that you are trying to build the same target multiple times:

rosidl_generate_interfaces(${PROJECT_NAME}
  "msg/Age.msg"
)
rosidl_generate_interfaces(${PROJECT_NAME}
  "srv/MyCustomServiceMessage.srv"
)

Instead, you should use the same target for both messages:

rosidl_generate_interfaces(${PROJECT_NAME}
  "msg/Age.msg"
  "srv/MyCustomServiceMessage.srv"
)

Best,

2 Likes

That was the issue, thank you so much!

1 Like