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

When to call generate_message() in CMakeLists.txt

asked 2013-08-28 20:40:39 -0600

munnveed gravatar image

Do I need to call generate_message() when I am only using a message defined in another package, and not defining one in my package?

It seems like I should not, since the code for the messages are already generated in the package defining it, which I am including. But the tutorial "Writing a Simple Publisher and Subscriber (C++)" has a call to generate_message() even though it only uses the std_msgs/String message, and does not define any of its own.

Can someone clarify the situation?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
4

answered 2013-08-28 21:46:48 -0600

Dirk Thomas gravatar image

The tutorial seem to be wrong in several aspects.

If your package does not contain message/service files you should not invoke that function.

But when you use messages/services from other packages at compile time (e.g. including generated message headers) your targets (executables as well as libraries) should have an explicit dependency on the target which generates the code. catkin supports you in identifying which targets generate code so that you can add a dependency on all exported target from packages which you have find_package() before:

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

Comments

This makes sense. I want to clarify one thing though. I need the add_dependency() only if it is one of the packages I am building that has the code generating target, right? If I am using a message from std_msgs for example, I don't need the add_dependency()?

munnveed gravatar image munnveed  ( 2013-08-28 22:12:41 -0600 )edit

std_msgs should also generate messages, although in most cases you'd already have them from a system install.

dornhege gravatar image dornhege  ( 2013-08-28 23:34:55 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2013-08-28 20:40:39 -0600

Seen: 3,289 times

Last updated: Aug 28 '13