# Using catkin to install libraries

I currently have a series of 3rd party libraries that I want to package for easier building and use. The idea is that they are each contained in a catkin_project file that looks like this: (Note: libboost is just an example package)

CMakeFiles.txt

cmake_minimum_required( VERSION 2.8.3 )

project( lib_boost )

catkin_package()

install( DIRECTORY include/
DESTINATION ${CATKIN_GLOBAL_INCLUDE_DESTINATION}/${PROJECT_NAME} )

install( DIRECTORY lib/
DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}/${PROJECT_NAME} )


package.xml

<package format="2">

<name>lib_boost</name>

<version>1.0.0</version>

<description> -- </description>

<maintainer email="--"> -- </maintainer>

<buildtool_depend>catkin</buildtool_depend>

<export>
</export>
</package>


When I try to include this into the main system I do it in the following way: cmake_minimum_required( VERSION 2.8.3 )

project( project_ros CXX )

find_package( catkin REQUIRED COMPONENTS    lib_boost
roscpp
std_msgs
sensor_msgs
message_runtime )

## Add all of the include directories defined by the packages listed above
include_directories( include ${catkin_INCLUDE_DIRS} ) catkin_package( CATKIN_DEPENDS message_runtime lib_boost INCLUDE_DIRS ) set( ROS_PROJECT_SOURCE src/main.cpp ) ## Create the linis_ros executable add_executable( project_ros${ROS_PROJECT_SOURCE} )


Package.xml

<?xml version="1.0"?>

<package format="2">

<name>project_ros</name>

<version>1.0.0</version>

<description>---</description>

<maintainer email="--">--</maintainer>

<buildtool_depend>catkin</buildtool_depend>

<build_depend>message_runtime</build_depend>
<build_depend>lib_boost</build_depend>

<exec_depend>message_runtime</exec_depend>
<exec_depend>lib_boost</exec_depend>

</package>


The output of both catkin_make -j1 and catkin_make install -j1 both throw the following error:

No such file or directory


When I look in the install directory there is nothing in the include portion but if i remove my package and then run catkin_make install the libraries will put their files into the proper spots but when i replace my package and run catkin_make it is still unable to find the header files I know are in the proper locations.

edit retag close merge delete

Sort by » oldest newest most voted

install rules are valid for install space, but they're not the whole picture. cmake also requires Package-config.cmake files which tell it how to find your package, which libraries to include, etc.

When building with catkin_make, you're building in a development workspace, which is faster than running all of the install rules, but it also means that files aren't installed.

The catkin_package() call is designed to address both of these - it generates the requisite files so that other cmake files can find this project, and it allows other packages in your devel space to find your project.

To use catkin_package() correctly, you need to give it your install directory, any libraries that downstream packages should link to, any external dependencies that downstream projects need when building, and any catkin dependencies that downstream projects need when building.

For example (and I'm making things up because you're making things up), if your package has all of its includes in the include directory, and it builds a library called libmypacakge (with a cmake target name of mypackage), and it depends on roscpp (catkin package) and ffmpeg (external package), then your catkin_package call would look something like:

catkin_pacakge(
INCLUDES include
LIBRARIES mypacakge
DEPENDS ffmpeg # same name you used to find the package earlier
CATKIN_DEPENDS roscpp
)


If your package has headers that include the roscpp headers and the ffmpeg headers, this guarantees that their include directories will be on the include path for anyone who uses your library. (same for libraries).

more

Thank you so much by adding the INCLUDES portion to the catkin_package for the libraries I am installing it can now find them.

I hadn't quite grasped that I needed this in the catkin_package call to let other package know about it.

( 2016-04-06 00:15:57 -0500 )edit

Is it possible to use the catkin_package() call to have the system provide libraries even if you don't build them and are just redistributing them?

( 2016-04-06 11:31:35 -0500 )edit

Yes, but it's a little more complicated. See https://github.com/ros-drivers/prosil... for an example.

( 2016-04-06 12:35:11 -0500 )edit

## Stats

Seen: 1,400 times

Last updated: Apr 06 '16