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

catkin: how to set up build dependencies of two packages correctly?

asked 2014-02-17 23:08:49 -0600

psei gravatar image

Hello dear ROS-community!

I am currently struggeling with the setup of "CMakeLists.txt" and "package.xml" of two selfmade catkin packages. To my eyes it does not seem to be a very complicated situation, but somehow I am not able to make it work...

Here is the situation: Package A builds a c++ library, Package B uses and links against this library.

From my understanding, the CMakeLists.txt of Package A should therefore look something like this:

CMakeLists.txt Package A:

cmake_minimum_required(VERSION 2.8.3)
project(Package_A)
find_package(catkin REQUIRED COMPONENTS
 roscpp
 rospy
)

catkin_package(
INCLUDE_DIRS include 
LIBRARIES libmylibrary.so 
CATKIN_DEPENDS roscpp rospy
# DEPENDS system_lib
)

Package.xml Package A:

<name>Package_A</name>
<version>0.0.0</version>
<description>The A package</description>
<maintainer email="foo@bar.de">foobar</maintainer>
<license>TODO</license>
<buildtool_depend>catkin</buildtool_depend>
<build_depend>roscpp</build_depend>
<build_depend>rospy</build_depend>
<run_depend>roscpp</run_depend>
<run_depend>rospy</run_depend>

So now here comes package B, which needs the library of Package A:

CMakeLists.txt Package B:

cmake_minimum_required(VERSION 2.8.3)
project(Package_B)
find_package(catkin REQUIRED COMPONENTS
 roscpp
 rospy
 Package_A
)

catkin_package(
# INCLUDE_DIRS include 
# LIBRARIES libmylibrary.so 
CATKIN_DEPENDS Package_A
# DEPENDS system_lib
)

Package.xml Package B:

<name>Package_B</name>
<version>0.0.0</version>
<description>The B package</description>
<maintainer email="foo@bar.de">foobar</maintainer>
<license>TODO</license>
<buildtool_depend>catkin</buildtool_depend>
<build_depend>roscpp</build_depend>
<build_depend>rospy</build_depend>
<build_depend>Package_A</build_depend>
<run_depend>roscpp</run_depend>
<run_depend>rospy</run_depend>
<run_depend>Package_A</run_depend>

In this configuration, it is not possible to run "catkin_make", it will stop with the following error:
Project 'Package_B' tried to find library 'libmylibrary.so'. The library is neither a target nor built/installed properly. Did you compile project 'Package_A'?

Why doesn't catkin see the dependency and build the library first, so that the other package can find it?

My only workaround at the moment is to remove the dependencies, build the library stand-alone, put the dependency back in and then build the rest. What am I doing wrong?

Thanks for your answers

edit retag flag offensive close merge delete

Comments

Is this copy-paste from your actual CMakeLists.txt? Cause there is no add_library() statement in Package_A's CMakeLists.txt, so no library would be ever build?

gvdhoorn gravatar image gvdhoorn  ( 2014-02-17 23:51:25 -0600 )edit

Yes, it is copy-paste from my CMakeLists, but I think "add_library()" is not necessary. See my solution below, I needed to change the name of the library, so CMake can identify it as a target.

psei gravatar image psei  ( 2014-02-18 00:10:01 -0600 )edit

add_library is definitely necessary. That is the CMake command to create a library target.

Dirk Thomas gravatar image Dirk Thomas  ( 2014-02-18 05:00:50 -0600 )edit

Yeah I see that now, i misunderstood the first comment of gvdhoorn.... Of course add_library() is needed. What I posted is not the complete makefile, just the parts where the catkin dependencies are configured. Building at all was not my problem, but making those packages build together didn't work.

psei gravatar image psei  ( 2014-02-18 05:25:25 -0600 )edit

2 Answers

Sort by ยป oldest newest most voted
1

answered 2014-02-17 23:48:03 -0600

psei gravatar image

The Problem can be solved by changing "libmylibrary.so" to "mylibrary" in the following lines of CMakeLists.txt of Package A:

from:

catkin_package(
INCLUDE_DIRS include 
LIBRARIES libmylibrary.so 
CATKIN_DEPENDS roscpp rospy
# DEPENDS system_lib
)

to:

catkin_package(
INCLUDE_DIRS include 
LIBRARIES mylibrary
CATKIN_DEPENDS roscpp rospy
# DEPENDS system_lib
)
edit flag offensive delete link more
2

answered 2014-02-18 05:02:41 -0600

Dirk Thomas gravatar image

updated 2014-02-18 05:03:58 -0600

You first need to use add_library() in package A. In package B you will need an add_executable().

After that is done you need to tell CMake about the dependency between both using:

add_dependencies(myexecutable ${catkin_EXPORTED_TARGETS})

Please consider reading the catkin tutorials as well as documentation: http://wiki.ros.org/catkin/Tutorials and http://docs.ros.org/api/catkin/html/

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2014-02-17 23:08:49 -0600

Seen: 9,109 times

Last updated: Feb 18 '14