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

Catkin unable to include custom libraries

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

heuristicus gravatar image

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

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
)

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

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>

  <license>TODO</license>

  <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 flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
4

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

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

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>

In your case:

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

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

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

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

edit flag offensive delete link more

Comments

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 -0500 )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.

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

Question Tools

1 follower

Stats

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

Seen: 4,894 times

Last updated: Oct 21 '14