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

First compile with messages, messages not found

asked 2013-08-15 03:38:28 -0500

Hansg91 gravatar image

Hello,

I am using a catkin workspace with a package that only contains messages. If I build the workspace for the first time (ie. delete the devel / build folders) it seems like it wants to compile code that depends on these messages, before it has build these messages. This results in an error saying it can't find the message include file.

If I then try to compile it again it works fine, because then the messages are probably generated. In packages that depend on the messages I add this in the CMakeLists.txt:

generate_messages(
  DEPENDENCIES
  eva_msgs  # Or other packages containing msgs
)

But that doesn't seem to have any effect. It is not a big deal since I can just compile it twice the first time, but I would like to fix it still.

Regards, Hans

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
11

answered 2013-08-15 04:36:26 -0500

This is a common issue people have with catkin. See here, here, and here.

Your assessment is correct that the executable is being built before the message headers. In catkin, you must explicitly tell cmake that your code depends on those message targets to ensure the build order gets resolved correctly. The catkin how-to suggests that the best way to resolve this is to add the following line to your CMakeLists.txt:

add_dependencies(your_program ${catkin_EXPORTED_TARGETS})

This will force your code to build after all its listed dependencies, which is safe, but maybe more conservative than required. I haven't tried it, but the solution listed here suggests that you can, instead, use the following line to explicitly state that you're depending on the message-headers only:

add_dependencies(your_program msg_pkg_generate_messages_cpp)

That last method is used in the wiki tutorial on custom messages.

edit flag offensive delete link more

Comments

Aha I see, I found it quite hard what to search for but that helped. The _generate_messages_cpp suffix didn't work for me, _gencpp as mentioned in that issue did. Perhaps my groovy is a bit outdated. I find it strange though, since in the package.xml I already mention it depends on my msgs package.

Hansg91 gravatar image Hansg91  ( 2013-08-15 04:53:38 -0500 )edit

I agree, it is confusing. In catkin, you must explicitly specify build dependencies in CMakeLists.txt independently of what's specified in the package.xml. This is done in two steps: 1) find the req'd package (find_package), 2) add the dependencies (target_link_libraries, add_dependencies, etc.)

Jeremy Zoss gravatar image Jeremy Zoss  ( 2013-08-15 05:00:21 -0500 )edit

+1, works for me.

SR gravatar image SR  ( 2015-08-11 04:08:18 -0500 )edit

Thanks, the add_dependencies for _generate_messages_cpp plus your three links worked. I also forgot message_generation among CMakeLists.txt dependencies so now I use two CMake variables for dependency and message packages and I pass them to find_package, catkin_package and generate_messages.

Avio gravatar image Avio  ( 2018-06-12 07:15:32 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2013-08-15 03:38:28 -0500

Seen: 14,127 times

Last updated: Aug 15 '13