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

add a custom library?

asked 2011-08-10 23:28:43 -0500

flamenco gravatar image

updated 2014-01-28 17:10:11 -0500

ngrennan gravatar image

Hi there!

I am a robotics hobbyist and just started with ROS. I have a custom library (lets call it customLibrary-1.0) that I would like to integrate in my first ROS node. It is my first time using cmake (I am used to autotools) so I am a bit lost with it.

Usually to compile a program that uses the custom library I would do something like:

g++ -o myprogram myprogram.cpp `pkg-config customLibrary-1.0 --cflags --libs`

The only special thing about customLibrary-1.0 is that it depends on otherCustomLibrary-3.0, but pkg-config takes care of that for me. The result of the pkg-config command would be something like:

-I/usr/local/include/customLibrary-1.0 -I/usr/local/include/otherCustomLibrary-3.0 -L/usr/local/lib -lcustomLibrary-1.0 -lotherCustomLibrary-3.0

How can I add that library into cmake? I have been reading other posts and surfed the web, but I am confused. Some people suggest using the macros: include_directories() and target_link_libraries(). In other places I read that I should write a file named findCustomLibrary-1.0.cmake full with a lot of macros. How do grown-ups do it? :D

Thanks in advance and sorry for the newbie question.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2011-08-11 00:21:08 -0500

dornhege gravatar image

updated 2011-08-11 00:23:36 -0500

CMake supports finding libraries, see here. Once you have applied the check... macros you use the variables in include_directories/target_link_libraries, e.g.


edit flag offensive delete link more


Awesome! I had skimmed-trough cmake documentation but didn't pay attention to FindPkgConfig :S
flamenco gravatar image flamenco  ( 2011-08-11 13:42:35 -0500 )edit

answered 2011-08-10 23:43:53 -0500

flamenco gravatar image

Hi again!

I tried adding this to the CMakeLists.txt file:

target_link_libraries(main /usr/local/lib/
target_link_libraries(main /usr/local/lib/

The compilation succeeds and the program works, but is there any more automatic way to do that?

Thanks a lot!

edit flag offensive delete link more


Instead of answering, you can edit your original post to add aditional information.
dornhege gravatar image dornhege  ( 2011-08-11 00:24:19 -0500 )edit
Oops!! Sorry about that!
flamenco gravatar image flamenco  ( 2011-08-11 13:37:22 -0500 )edit

Question Tools


Asked: 2011-08-10 23:28:43 -0500

Seen: 5,163 times

Last updated: Aug 11 '11