Ask Your Question
0

How to properly build include a small library/namespace in a ROS-Project

asked 2019-01-22 03:46:57 -0600

max11gen gravatar image

I have a ROS project consisting of several nodes each of which is built from the CMakeLists like this:

add_executable(node1 src/node1.cpp src/node1callback.cpp) target_link_libraries(node1 ${catkin_LIBRARIES}) add_dependencies(node 1 my_ros_project_generate_messages_cpp)

Now I would like to write a small library (not sure if this is the right word) consisting of a .h and a .cpp file defining a namespace with a couple of functions that I use in multiple nodes.
Now my question is: How do I add this library to the CMakeLists? Do I add it in the same way even though it's not a node?

edit retag flag offensive close merge delete

Comments

An observation: please realise this is not ROS-specific, but a general CMake workflow question. add_library(..) as suggested by @Sebastian Kasperski is a regular CMake function, and the rest of the additions/changes to your CMakeLists.txt would be as well.

gvdhoorn gravatar imagegvdhoorn ( 2019-01-22 04:03:54 -0600 )edit

@gvdhoorn You are right, sorry. I'll consider other forums the next time.

max11gen gravatar imagemax11gen ( 2019-01-22 05:04:50 -0600 )edit
2

@max11gen: I did not make my comment to tell you to go to other fora. I merely wanted to make sure you did not assume this was something ROS-specific.

Many times I've had to explain that Catkin is essentially "some" convenience macros for CMake. Just wanted to make sure you understood that.

gvdhoorn gravatar imagegvdhoorn ( 2019-01-22 05:11:50 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
2

answered 2019-01-22 03:59:09 -0600

Sebastian Kasperski gravatar image

Yes, you just use add_library instead of add_executable. Make sure to add your library to the target_link_libraries afterwards.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2019-01-22 03:46:57 -0600

Seen: 353 times

Last updated: Jan 22