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

How to link a common module in more packages?

asked 2013-12-11 22:06:23 -0500

eds gravatar image

updated 2014-01-28 17:18:48 -0500

ngrennan gravatar image

Hello,

I have some ROS C++ packages that share many common functions.

They are identical functions so I was thinking to put them all in another file.hpp and include this file in each package is needing them.

I'm using catkin to create my workspace and all the packages I develop. They are all in src directory starting from the main one, as the tutorials said.

But where do I must save this file.hpp in the workspace and which path I have to #include in each file that is using it? Do I have to modify the CMakeLists.txt?

This is a scheme of my workspace:

  • build
  • devel
  • src

    package 1

    CMakeLists.txt

    src (file.cpp are here)

    include

    package1.xml

    package 2

    ...

Thanks in advance.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
2

answered 2013-12-12 03:47:17 -0500

joq gravatar image

updated 2013-12-12 03:48:55 -0500

The library package @dornhege recommends should be built like this:

If you only provide headers and no libraries, skip the library build and installation instructions. But, you should install the headers.

You other packages will reference it like this:

edit flag offensive delete link more
2

answered 2013-12-11 22:52:21 -0500

dornhege gravatar image

The ROS way would be to create a package for these common functions. The common code goes in there either as a header or built as a library.

All other packages that need this would then just depend on this package.

edit flag offensive delete link more

Comments

Thank you, can you make an example? I can create a package but how do I must make the others dependable by this one? Do I have to put some extra #include, CMakeLists or package.xml statement?

eds gravatar image eds  ( 2013-12-11 23:05:57 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2013-12-11 22:06:23 -0500

Seen: 287 times

Last updated: Dec 12 '13