Ask Your Question

Trouble with Catkin: Compiling node and generating messages in same package.

asked 2013-06-06 06:12:36 -0600

Raptor gravatar image

updated 2013-06-12 22:48:38 -0600

130s gravatar image

Hi Guys,

I am currently catkinizing the ublox driver found here:

The node "ublox_msgs" builds a library and generates a number of messages at the same time. The library that is built in the package depends on the generated message header files that is created during compile time.

The problem is that it tries to compile the library without waiting for all the message headers to all be generated. The result is a error that it can not find one of the generated header files. For example:

../../ublox_msgs/include/ublox_msgs/ublox_msgs.h:41:35: fatal error: ublox_msgs/NavTIMEGPS.h: No such file or directory

I can see the messages being generated, and if I run "cakin_make" multiple times, it will generate all the headers and no longer error out. But I would like it to generate the message headers and then compile the library, so a error does not happen. I know the library and the messages should probably be in separate packages, but I just wanted to get it working in its current state.

I tried following what was referenced in this post, but it did not seem to work either:

Here is my package.xml file:

<?xml version="1.0"?>

  <maintainer email="">Jane Doe</maintainer>





Here is my CMakeLists.txt file:

cmake_minimum_required(VERSION 2.8.3)

find_package(catkin REQUIRED COMPONENTS genmsg ublox_serialization roscpp)

## Generate messages in the 'msg' folder

## Generate added messages and services with any dependencies listed here

   INCLUDE_DIRS include
#  CATKIN_DEPENDS message_runtime
#  DEPENDS ublox_msgs


## Declare a cpp library

## Add cmake target dependencies of the executable/library
## as an example, message headers may need to be generated before nodes
add_dependencies(${PROJECT_NAME} ${PROJECT_NAME}_gencpp)

## Specify libraries to link a library or executable target against
target_link_libraries(${PROJECT_NAME} ${catkin_LIBRARIES})

I tried to follow the tutorials as much as possible:

Does anyone see a issue in these files? Or maybe there is still a bug in Catkin?

Thank you for your help.


So it looks like it works with catkin_make -j1 but NOT with just catkin_make. So it seems to be possibly a bug with running multiple jobs at once ... (more)

edit retag flag offensive close merge delete


Can you post the entire output of catkin_make -j1 on a previously unbuilt workspace? Your package looks ok to me, I don't see why you would be getting the out of order build bug (I can pretty confidently confirm that this is that bug since you can resolve it by running multiple times).

William gravatar image William  ( 2013-06-06 10:42:24 -0600 )edit

Look at update above.

Raptor gravatar image Raptor  ( 2013-06-07 03:51:11 -0600 )edit

Why is CATKIN_DEPENDS message_runtime commented out? What happens when you use it?

joq gravatar image joq  ( 2013-06-07 07:01:16 -0600 )edit

I do not see a difference if I use it or not, at least during compile time.

Raptor gravatar image Raptor  ( 2013-06-07 07:12:42 -0600 )edit

I think it is needed for other catkin packages that use your messages.

joq gravatar image joq  ( 2013-06-07 07:15:00 -0600 )edit

Alright I will keep that in then.

Raptor gravatar image Raptor  ( 2013-06-07 07:20:28 -0600 )edit

4 Answers

Sort by ยป oldest newest most voted

answered 2013-06-06 11:56:07 -0600

joq gravatar image

updated 2013-06-07 03:58:06 -0600

UPDATED to remove incorrect suggestion, see comments below.

The currently-recommended variable name for expanding self-defined messages and services is:

add_dependencies(uuid_msgs ${${PROJECT_NAME}_EXPORTED_TARGETS})

I wrote that using the uuid_msgs target, because others reading this question may be confused by the fact that your library target has the same name as your package.

edit flag offensive delete link more


I think that ${${PROJECT_NAME}_gencpp} will not work, that would be dereferencing a target (${PROJECT_NAME}_gencpp is a target). The second recommendation is definitely correct.

William gravatar image William  ( 2013-06-06 11:58:34 -0600 )edit

The line from above: "add_dependencies(${PROJECT_NAME} ${${PROJECT_NAME}_gencpp})" does not seem to work. Here is the error that is produced: "CMake Error at ublox_msgs/CMakeLists.txt:108 (add_dependencies): add_dependencies called with incorrect number of arguments"

Raptor gravatar image Raptor  ( 2013-06-07 03:15:00 -0600 )edit

Sorry for the mistake. I thought it was a CMake variable, but as @William said, it's a target. I'll update the answer. Did the other add_dependencies() work for you?

joq gravatar image joq  ( 2013-06-07 03:55:47 -0600 )edit

No problem, I thank you guys for the help. I put the command "add_dependencies(ublox_msgs ${PROJECT_NAME}_EXPORTED_TARGETS)" in place of "add_dependencies(${PROJECT_NAME} ${PROJECT_NAME}_gencpp)" and got the same error, that it could not find one of the generated header files from the messages.

Raptor gravatar image Raptor  ( 2013-06-07 04:14:31 -0600 )edit

Don't forget the double evaluation: ${${PROJECT_NAME}_EXPORTED_TARGETS}

joq gravatar image joq  ( 2013-06-07 04:32:13 -0600 )edit

If I add the double evaluation, "add_dependencies(ublox_msgs ${${PROJECT_NAME}_EXPORTED_TARGETS})" I get the cmake error: "CMake Error at ublox_msgs/CMakeLists.txt:68 (add_dependencies): add_dependencies called with incorrect number of arguments" like the one above.

Raptor gravatar image Raptor  ( 2013-06-07 04:39:01 -0600 )edit

What does message("exported targets: ${${PROJECT_NAME}_EXPORTED_TARGETS}") print? Sounds like it must be empty.

joq gravatar image joq  ( 2013-06-07 04:44:31 -0600 )edit

It is empty. I guess I am unclear on how to use it. This is the only resource I found that has any documentation on it: and it does not tell you how to really use it.

Raptor gravatar image Raptor  ( 2013-06-07 06:13:43 -0600 )edit

answered 2013-06-07 08:04:56 -0600

jbohren gravatar image

updated 2013-06-07 08:06:13 -0600

Since targets are now built with plain CMake macros (add_executable, add_library, etc), there's no longer a list of targets built by a given package, and thus, a dependency cannot be made on messages first. What you need to do, for a given project is explicitly add a dependency on the CMake target representing the message generation step for that language. If the project name is "foo_pkg" and is written in c++ then this target names is "foo_pkg_gencpp" in CMakeLists.txt this looks like:

# ...
# For a library
add_library(foo src/foo_lib.cpp)
add_dependencies(foo ${PROJECT_NAME}_gencpp)
# For an executable
add_executable(foo_node srd/foo_node.cpp)
add_dependencies(foo_node ${PROJECT_NAME}_gencpp)

This is actually documented here (maybe it could be put in a more obvious place):

See an example here:

edit flag offensive delete link more


I believe this is what I have. Could the problem be that the project_name is the same as the library name?

Raptor gravatar image Raptor  ( 2013-06-07 08:28:49 -0600 )edit

No, that wouldn't be a problem. They're also the same in control_toolbox.

jbohren gravatar image jbohren  ( 2013-06-07 08:31:41 -0600 )edit

His code does this and this will be deprecated in favor of using the ${PROJECT_NAME}_EXPORTED_TARGETS cmake variable, see:!msg/ros-sig-buildsystem/dvVO5QCHBLM/_Ry8ioEGmpgJ

William gravatar image William  ( 2013-06-07 08:36:05 -0600 )edit

Here is the repository with the code that is producing this error:

Raptor gravatar image Raptor  ( 2013-06-07 10:18:37 -0600 )edit

answered 2013-06-07 11:05:36 -0600

William gravatar image

The error is occurring in the ublox_gps package not the ublox_msgs package, which is setup correctly. I have addressed the problem and given some other feed back in a pull request:

edit flag offensive delete link more


I pulled down the pull request and it still reports a error. I commented on the pull request the error.

Raptor gravatar image Raptor  ( 2013-06-10 04:06:40 -0600 )edit

I commented on the pull request I think that you'll have to use the target name explicitly, ublox_msgs_generate_messages_cpp, until you start using genmsg >= 0.4.18, which should be in public repositories in a week or so.

William gravatar image William  ( 2013-06-10 06:28:38 -0600 )edit

answered 2015-05-28 15:32:12 -0600

TinGoose gravatar image

Good day.

Seems like we have the similar issue. We have core project 'sybo_base' that defines some messages and nodes ('broadcaster', 'feeder') that use this message, and several other projects in the workspace that depend on sybo_base.

We've specified all the sort of dependencies for target (tried all of mentioned variants):

add_executable(broadcaster broadcaster.cpp utils.cpp)
add_dependencies(broadcaster ${${PROJECT_NAME}_EXPORTED_TARGETS})

And it anyways tries to build target 'broadcaster' before 'sybo_base_generate_messages_cpp' I've tried to check actual contents of mentioned variables

message(STATUS "broadcaster needs the following targets ${${PROJECT_NAME}_EXPORTED_TARGETS}")
target_link_libraries(broadcaster ${catkin_LIBRARIES} sybo_base)

CMake has produced the following output:

-- sybo_base: 5 messages, 2 services
-- sybo_base includes :/opt/ros/indigo/include;/usr/include
-- broadcaster needs the following targets sybo_base_generate_messages_cpp;sybo_base_generate_messages_lisp;sybo_base_generate_messages_py

It looks ok, the necessary dependencies are listed. When i try to build sybo_base 'separately', like

cd catkin_ws/build
make -j4 sybo_base

it builds nice. But when I try to build full workspace (of ~12 catkin projects in it) - build fails because of building 'broadcaster' before generating messages for it

edit flag offensive delete link more



As mentioned on the issue you filled please post the complete CMake code as well as the exact error message. If I have to guess based on you incomplete snippet you lack the dependencies for the sybo_base target.

Dirk Thomas gravatar image Dirk Thomas  ( 2015-05-28 16:01:47 -0600 )edit

Also please don't your question as an answer. Better ask a new question and reference it in a comment.

Dirk Thomas gravatar image Dirk Thomas  ( 2015-05-28 16:02:55 -0600 )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



Asked: 2013-06-06 06:12:36 -0600

Seen: 9,803 times

Last updated: Jun 07 '13