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

How to add external libraries to ROS cpp file?

asked 2020-01-15 08:58:58 -0600

Yehor gravatar image

updated 2022-01-22 16:10:15 -0600

Evgeny gravatar image


Could someone explain the proper way how to link external libraries to ros cpp node in the cmake. For example I want to use libserial in my node to control the driver. Fro that I have installed the lib by using this commands:

sudo apt install libserial-dev

And now I have to link that lib in the cmake

Thanks in advance!

edit retag flag offensive close merge delete


Maybe it's outdated but you could try this

Solrac3589 gravatar image Solrac3589  ( 2020-01-15 09:22:59 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2020-02-12 01:13:48 -0600

Yehor gravatar image

updated 2020-02-12 01:14:24 -0600

I want to answer my own question, to clarify which way I found and what is the proper as I consider.

Basically, you have to add folder with header files and the library itself. You can do it with find_package, or manually.

The header files you have to include in "include_libraries" like I did:

include_directories( ${catkin_INCLUDE_DIRS} ${Qt5Core_INCLUDE_DIRS} ${Qt5WebSockets_INCLUDE_DIRS} /usr/include )

And the library itself, you can add with "target_link_libraries", like this:

add_executable(driver src/driver_node.cpp) target_link_libraries(driver ${catkin_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} /usr/lib/aarch64-linux-gnu/

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2020-01-15 08:58:58 -0600

Seen: 988 times

Last updated: Feb 12 '20