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

How can I create my own ROS C++ library?

asked 2013-03-15 07:55:39 -0500

Nishant gravatar image

updated 2014-01-28 17:15:45 -0500

ngrennan gravatar image

Hello All,

This might be a repeat question (although I checked out some of the recommendations that ROS Answers asked me to look at while typing the title of this question, but they didn't seem relevant). Here goes.

So I have a C++ header file called "force_torque.h" (I had issues with this, but thanks to @jbohren I was able to fix those) and I want to convert it into a ROS library. So basically, I want it to be a valid ROS package, yet I also want other ROS packages to be able to depend on this package. So far, I have just been able to create a new package using 'roscreate-pkg'. Now I have a feeling that I need to modify "CMakeLists.txt" somehow, but I don't know how. Is there any good ROS tutorial on how to do this? Or if it could be described here on this question below, I would be very grateful.

Thanks, and all help is greatly appreciated!


edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted

answered 2013-03-15 16:44:37 -0500

jbohren gravatar image

In rosbuild, to build the library you use rosbuild_add_library shown here, which is similar to the standard CMake add_library function. Then to make it available to other ros packages, you add the library linker arguments to a <cpp> export tag in the package's manifest.xml shown here.

In catkin, you use the normal add_library CMake function to build the library. Then to make the library available to other ros packages, you add the library target to the LIBRARIES arguments of a call to the catkin_package CMake macro, shown here.

edit flag offensive delete link more


@jbohren : Thanks! I'll follow the links that you have provided, and see where it takes me. I'll post any roadblocks that I hit on this thread itself. Thanks once again!

Nishant gravatar image Nishant  ( 2013-03-19 10:48:28 -0500 )edit

answered 2013-03-17 19:49:08 -0500

jbohren's answer is good. The wiki also provides some additional examples that show how to set up your CMakeLists.txt for different needs.

Alternatively, you could use the technique shown here to simply make an existing library available to the ROS system. For linking, dependencies, etc. That link suggests this method is deprecated, but I haven't found good documentation on the recommended replacement method.

edit flag offensive delete link more



I updated the link on the tutorial page to point to the new Bloom Tutorial:

tfoote gravatar image tfoote  ( 2013-03-17 22:08:46 -0500 )edit

@Jeremy Zoss: Thanks Jeremy! These examples look good! They should help me get started. @tfoote : Thanks for the link update, I'll check that too.

Nishant gravatar image Nishant  ( 2013-03-19 10:49:45 -0500 )edit

Question Tools

1 follower


Asked: 2013-03-15 07:55:39 -0500

Seen: 10,630 times

Last updated: Mar 17 '13