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

Wrap external library as catkin package

asked 2017-04-23 13:30:00 -0600

inspire gravatar image

updated 2017-04-23 13:30:59 -0600

Hi,

I have a precompiled library that I want to use in multiple catkin packages. Hence, I want to wrap this external library with a catkin package which then can be used in other packages with the XML command <build_depend>wrapper_library</build_depend> and the cmake command find_package(wrapper_library). Can you tell me which commands must be included in the cmakelists file of the wrapper_library such that it easily provides the wrapped library to other packages? Do these other catkin packages need more commands like the target_link_libraries(mypackage wrapper_library)? I don't really know how to start because this use case is not documented in the Ros tutorials, I think... And I am no cmake expert :)

Thanks in advance!

inspire

edit retag flag offensive close merge delete

Comments

Do you have the source code?

mohsen1989m gravatar image mohsen1989m  ( 2017-04-23 13:39:05 -0600 )edit

Do you have the source code? lib.cpp and lib.h files

mohsen1989m gravatar image mohsen1989m  ( 2017-04-23 13:39:18 -0600 )edit

Yeah and I am able to automatically compile it with a similar catkin wrapper. But this library only compiles with things like autoconf etc installed. Hence, I thought about pre-compiling the library to remove the necessity to have autoconf etc installed. Or do you have another idea?

inspire gravatar image inspire  ( 2017-04-23 13:53:29 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
2

answered 2017-04-23 16:06:13 -0600

mohsen1989m gravatar image

You can take a look at this example of one of my packages. Where I create a library "costmap2d" out of my source files costmap.cpp and cnmap.cpp then I share it in my workspace so i would be able to use it by other packages. here I assumed you lib depends on an example external lib named xxx.

cmake_minimum_required(VERSION 2.8.3)
project(costmap)


find_package(catkin REQUIRED COMPONENTS
  geometry_msgs
  nav_msgs
  roscpp
  std_msgs
  tf
  xxx
)


catkin_package(
  INCLUDE_DIRS include
  LIBRARIES costmap2d
  CATKIN_DEPENDS geometry_msgs nav_msgs roscpp std_msgs tf xxx
  DEPENDS system_lib
)

include_directories(
  ${catkin_INCLUDE_DIRS}
)

add_library(costmap2d include/${PROJECT_NAME}/costmap.cpp include/${PROJECT_NAME}/cnmap.cpp)
target_link_libraries(costmap2d   xxx
   ${catkin_LIBRARIES}
)

install(TARGETS costmap2d
   ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
   LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
   RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
 )

note that here I am sharing this lib across the ws meaning that other packages of mine can also use it. if you just want to use if inside your package you don't need to install

edit flag offensive delete link more

Comments

thanks, that helped a lot!

inspire gravatar image inspire  ( 2017-04-28 11:59:14 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2017-04-23 13:30:00 -0600

Seen: 1,833 times

Last updated: Apr 23 '17