0
$\begingroup$

Rosanswers logo

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


Originally posted by Hansg91 on ROS Answers with karma: 1909 on 2013-08-15

Post score: 8

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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.


Originally posted by Jeremy Zoss with karma: 4976 on 2013-08-15

This answer was ACCEPTED on the original site

Post score: 11


Original comments

Comment by Hansg91 on 2013-08-15:
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.

Comment by Jeremy Zoss on 2013-08-15:
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.)

Comment by SR on 2015-08-11:
+1, works for me.

Comment by Avio on 2018-06-12:
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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.