ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A answers.ros.org

# Catkin unable to include custom libraries

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.

CMakeLists.txt:

cmake_minimum_required(VERSION 2.8.3)
project(proj_util)

find_package(catkin REQUIRED COMPONENTS
roscpp
sensor_msgs
)

catkin_package(
LIBRARIES visionutil rosutil
)



package.xml

<?xml version="1.0"?>
<package>
<name>proj_util</name>
<version>0.0.0</version>
<description>Package for utility libraries</description>

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

<buildtool_depend>catkin</buildtool_depend>
<build_depend>roscpp</build_depend>
<run_depend>roscpp</run_depend>
<buildtool_depend>opencv2</buildtool_depend>
<run_depend>opencv2</run_depend>

<export>
</export>
</package>


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)
project(motor_controller2)

find_package(catkin REQUIRED COMPONENTS roscpp std_msgs ras_arduino_msgs proj_util)

catkin_package(
CATKIN_DEPENDS roscpp std_msgs ras_arduino_msgs proj_util
)

include_directories(${catkin_INCLUDE_DIRS}) 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 catkin_package( LIBRARIES visionutil rosutil INCLUDE_DIRS include ) install(DIRECTORY include/${PROJECT_NAME}/
DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION})  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 librosutil.so and libvisionutil.so, 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 close merge delete ## 2 Answers Sort by » oldest newest most voted 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: catkin_package( LIBRARIES visionutil rosutil INCLUDE_DIRS include) include_directories( include${catkin_INCLUDE_DIRS})


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>


#include <proj_util/rosutil.hpp>

more

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 ) 

 install(DIRECTORY include/${PROJECT_NAME}/ DESTINATION${CATKIN_PACKAGE_INCLUDE_DESTINATION} FILES_MATCHING PATTERN "*.h" PATTERN ".svn" EXCLUDE ) 

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

( 2014-10-21 09:07:10 -0600 )edit
1

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.

( 2014-10-21 11:50:23 -0600 )edit