Ask Your Question

catkin messages and node in same package

asked 2013-01-24 00:45:10 -0500

Dickvdsteen gravatar image

updated 2013-01-24 02:10:13 -0500


While working on some ROS node we bumped into the following problem:

We got a package containing a library, messages and services, the library is using these messages and services

The header files of the services and messages are generated succesfully, however when building the library, the error occurs that the header files of the messages and services are not found.

Is this due to the fact that services and messages should not be in a same packages as library or node?

the error looks like

header.h:34:27: fatal error: ns/header.h: No such file or directory compilation terminated.

Thank in advance

edit retag flag offensive close merge delete


@KruseT, thanks for your answer, i inspected the cmake and i dont think its a typo

Dickvdsteen gravatar image Dickvdsteen  ( 2013-01-24 01:57:45 -0500 )edit

Please provide the exact error message, failing code snippets and cmake files.

dornhege gravatar image dornhege  ( 2013-01-24 02:02:21 -0500 )edit

I noticed that the messages and services are generated after the library builds, for that reason it cant be found. However i call generate_messages before add_executable

Dickvdsteen gravatar image Dickvdsteen  ( 2013-01-24 02:06:22 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted

answered 2013-01-24 01:17:26 -0500

KruseT gravatar image

No, messages and services may lie in the same package as other code, though it is usually a good practice to put them into separate packages, to make the definitions reusable without the other code.

See the tutorial here, where messages and code are mixed:

So you may have made a typo somewhere in your package or message names instead.

edit flag offensive delete link more


I was having a similar issue, the message generation part may be quite tricky and requires some care. Please also refer to this answer and its links for more tips about the problem.

Avio gravatar image Avio  ( 2018-06-12 07:23:21 -0500 )edit

answered 2013-01-24 02:23:20 -0500

Dickvdsteen gravatar image

updated 2013-01-24 02:29:35 -0500

Solved it!

Seems the following line was needed after calling add library

add_dependencies(lib lib_gencpp)

is this the right way to do it or not?

edit flag offensive delete link more



This would be a bug, at least in the documentation. Is it possible for you to post the full CMakeLists.txt, so that we may reproduce?

KruseT gravatar image KruseT  ( 2013-01-24 11:20:22 -0500 )edit

The dependency is perfectly right assuming that your project is called "lib".If you build code which depends on generated C++ headers (which is usually the case) you need to tell CMake about that dependency else it may try to build the library before generating the headers for the messages.

Dirk Thomas gravatar image Dirk Thomas  ( 2013-01-24 21:00:10 -0500 )edit

Note that lib is a very bad name for a project or library. Choose library names which are prefixedwith your project names, and choose meaningful project names.

KruseT gravatar image KruseT  ( 2013-01-26 00:18:51 -0500 )edit
KruseT gravatar image KruseT  ( 2013-01-26 00:19:25 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2013-01-24 00:45:10 -0500

Seen: 4,347 times

Last updated: Jan 24 '13