Ask Your Question
0

How to add external libraries to ROS cpp file?

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

Yehor gravatar image

updated 2020-01-15 08:59:14 -0600

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 imageSolrac3589 ( 2020-01-15 09:22:59 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
0

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

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

1 follower

Stats

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

Seen: 28 times

Last updated: Feb 12