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

add a custom library?

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

flamenco gravatar image

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

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
2

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

dornhege gravatar image

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

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.

include_directories(${customLibary_INCLUDE_DIRS})

edit flag offensive delete link more

Comments

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 -0600 )edit
0

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

flamenco gravatar image

Hi again!

I tried adding this to the CMakeLists.txt file:

include_directories(/usr/local/include/customLibrary-1.0)
include_directories(/usr/local/include/otherCustomLibrary-3.0)
target_link_libraries(main /usr/local/lib/customLibrary-1.0.so)
target_link_libraries(main /usr/local/lib/otherCustomLibrary-3.0.so)

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

Comments

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

Question Tools

Stats

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

Seen: 5,246 times

Last updated: Aug 11 '11