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

How to add external libraries to ROS cpp file?

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

Yehor gravatar image

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

Evgeny gravatar image

Hello,

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

Comments

Maybe it's outdated but you could try this https://answers.ros.org/question/1278...

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

1 Answer

Sort by ยป oldest newest most voted
0

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

Yehor gravatar image

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

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/libserial.so)

edit flag offensive delete link more

Question Tools

1 follower

Stats

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

Seen: 1,032 times

Last updated: Feb 12 '20