0
$\begingroup$

Rosanswers logo

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.


Originally posted by eds on ROS Answers with karma: 101 on 2013-12-11

Post score: 0

$\endgroup$

2 Answers 2

0
$\begingroup$

Rosanswers logo

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:


Originally posted by joq with karma: 25443 on 2013-12-12

This answer was ACCEPTED on the original site

Post score: 2

$\endgroup$
0
$\begingroup$

Rosanswers logo

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.


Originally posted by dornhege with karma: 31395 on 2013-12-11

This answer was NOT ACCEPTED on the original site

Post score: 2


Original comments

Comment by eds on 2013-12-12:
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?

$\endgroup$

Your Answer

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