0
$\begingroup$

Rosanswers logo

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?


Originally posted by max11gen on ROS Answers with karma: 164 on 2019-01-22

Post score: 0


Original comments

Comment by gvdhoorn on 2019-01-22:
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.

Comment by max11gen on 2019-01-22:
@gvdhoorn You are right, sorry. I'll consider other forums the next time.

Comment by gvdhoorn on 2019-01-22:
@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.

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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


Originally posted by Sebastian Kasperski with karma: 1658 on 2019-01-22

This answer was ACCEPTED on the original site

Post score: 2

$\endgroup$

Your Answer

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