ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

Catkin unable to include custom libraries

asked 2014-10-21 07:46:49 -0600

heuristicus gravatar image

updated 2014-10-21 09:15:26 -0600

I have a package proj_util which is using the following catkin files, which seem to correctly generate the libraries and put them into ~/catkin_ws/devel/lib.


cmake_minimum_required(VERSION 2.8.3)

find_package(catkin REQUIRED COMPONENTS

  LIBRARIES visionutil rosutil

ADD_LIBRARY(visionutil src/math.cpp src/math.hpp)
ADD_LIBRARY(rosutil src/rosutil.cpp src/rosutil.hpp)


<?xml version="1.0"?>
  <description>Package for utility libraries</description>

  <maintainer email="ras@todo.todo">me</maintainer>




However, when I try and use the libraries in another package, compilation crashes, stating that the header file cannot be found. The CMakeLists.txt for the package in which I want to use the libraries look like this:

cmake_minimum_required(VERSION 2.8.3)

find_package(catkin REQUIRED COMPONENTS roscpp std_msgs ras_arduino_msgs proj_util)

  CATKIN_DEPENDS roscpp std_msgs ras_arduino_msgs proj_util


add_executable(motor_controller2 src/motorController2.cpp)
target_link_libraries(motor_controller2 ${catkin_LIBRARIES} rosutil)
add_dependencies(motor_controller2 ${catkin_EXPORTED_TARGETS})

I added references to the proj_util package to anywhere where it seemed relevant, but it didn't seem to make any difference. I also tried using the names of the libraries instead, but to no avail.

I've tried using numerous variations on #include <rosutil/rosutil.hpp>, but none of them seem to work. I tried using

  LIBRARIES visionutil rosutil
  INCLUDE_DIRS include
install(DIRECTORY include/${PROJECT_NAME}/

as recommended by this tutorial on building libraries, but even with this nothing seems to change.

I've tried to locate the files generated by the CMakeLists.txt for the library package, and other than the files used by make, the only files are and, located in ~/catkin_ws/devel/lib. Specifically, there are no references in any include directory to these library files.

What am I doing wrong?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2014-10-21 10:24:39 -0600

updated 2014-10-21 10:31:51 -0600

The easiest way is to have the package export its include directory as Gary mentioned. The install() call is not really necessary.

You should create a folder named include/ < name of package > / (include/proj_utils in your case) where you put all the header files (*.hpp) of the package.

Then the package that exports the library should have the following in the CMakeLists to be able to export the header files:

      LIBRARIES visionutil rosutil
      INCLUDE_DIRS include)


Then the other package should be able to see the header files as (you might have to run catkin_make or cmake first):

 #include <name_of_package/header_file.h>

In your case:

#include <proj_util/rosutil.hpp>
edit flag offensive delete link more

answered 2014-10-21 08:42:28 -0600

I think you need to add INCLUDE_DIRS to the CMakeLists.txt of your project (proj_util).

catkin_package( LIBRARIES visionutil rosutil INCLUDE_DIRS include )

and also install the headers


edit flag offensive delete link more


I had to add an include directory to the package in order to avoid an error (include dir include does not exist relative to [package path]), and it is not populated with anything after running catkin_make. Even with the install() call, I can't find either library in an include directory anywhere

heuristicus gravatar image heuristicus  ( 2014-10-21 09:07:10 -0600 )edit

You never need an empy include folder. If your package does not have headers just remove all references to include from your CMakeLists.txt file.

Dirk Thomas gravatar image Dirk Thomas  ( 2014-10-21 11:50:23 -0600 )edit

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


Asked: 2014-10-21 07:43:50 -0600

Seen: 4,762 times

Last updated: Oct 21 '14