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

Catkin: Use ROS message from another package

asked 2015-03-30 11:12:15 -0500

potAito gravatar image

Hi guys

I'm trying to use a ROS message defined in another package, lets say message_package in my own package which I will call myPackage. The problem I have is that catkin first tries to build myPackage before message_package. Hence I get a compilation error:

fatal error: message_package/msg.h: No such file or directory #include "message_package/msg.h"

I don't understand why catkin does that. In the package.xml of myPackage I added

<build_depend> message_package </build_depend>

and in the CMakeLists.txt I added

find_package(catkin REQUIRED COMPONENTS
message_package )

What else can I do to tell catkin to compile message_package BEFORE myPackage, so that the necessary headers are there?

edit retag flag offensive close merge delete



Why nobody upvotes question? :( (I gave u upvote, thanks)

martinerk0 gravatar image martinerk0  ( 2021-07-15 16:54:55 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2015-03-30 11:40:38 -0500

ahendrix gravatar image

You need to add a build-time dependency between your package and the packages you depend on. Assuming the node you're trying to compile is called your_executable, try:

add_dependencies(your_executable ${catkin_EXPORTED_TARGETS})
edit flag offensive delete link more


Huh it's working, thanks. I thought that's taken care of with build_depend. What exactly is ${catkin_EXPORTED_TARGETS}?

potAito gravatar image potAito  ( 2015-03-30 11:48:36 -0500 )edit

It is a CMake variable containing all the targets exported by packages you depend on. See: for details.

joq gravatar image joq  ( 2015-03-31 10:46:56 -0500 )edit

Aha! Thank you very much!

potAito gravatar image potAito  ( 2015-03-31 11:36:29 -0500 )edit

What will be your_executable ?

Mobeen gravatar image Mobeen  ( 2022-11-24 04:03:56 -0500 )edit

name of your .cpp file. Example add_dependencies(ros_ssa_single_agent ${catkin_EXPORTED_TARGETS}) # Followed example

icore-az gravatar image icore-az  ( 2022-12-14 12:14:52 -0500 )edit

Question Tools

1 follower


Asked: 2015-03-30 11:12:15 -0500

Seen: 16,278 times

Last updated: Mar 30 '15