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

ament_export_dependencies(Boost) not working?

asked 2019-08-19 18:47:39 -0600

DanRose gravatar image

I'm trying to use a library that depends on boost, and it doesn't seem like boost is properly being pulled in as a recursive dependency. How do I properly export the dependency on boost for downstream packages?

My build fails with:

/usr/bin/ld: CMakeFiles/slam_karto.dir/src/slam_karto.cpp.o: undefined reference to symbol '_ZN5boost6detail23get_current_thread_dataEv'
//usr/lib/x86_64-linux-gnu/ error adding symbols: DSO missing from command line
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [slam_karto] Error 1
make[1]: *** [CMakeFiles/slam_karto.dir/all] Error 2
make: *** [all] Error 2
Failed   <<< slam_karto [ Exited with code 2 ]

From my library CMake:

cmake_minimum_required(VERSION 3.5)
find_package(Boost REQUIRED COMPONENTS thread)
add_library(karto SHARED src/Karto.cpp src/Mapper.cpp)
ament_target_dependencies(karto Boost)

From the consuming package CMakeLists.txt:


I can make the error go away by changing the consuming package to have the following, but this is very bad practice:

find_package(Boost REQUIRED COMPONENTS thread)
edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted

answered 2019-09-06 12:22:39 -0600

Dirk Thomas gravatar image

The API docs of the ament_export_dependenciesfunctions ( describes the requirements what you can pass to it.

In your case of using Boost and requiring the component thread a simple find_package(Boost REQUIRED) call isn't sufficient. Since the API doesn't know about the COMPONENTS thread part it won't use it when downstream packages find your package and as a consequence they will fail to find the Boost thread symbols.

You will need to create a custom CMake file which finds the right component of Boost and register that file as a CONFIG_EXTRAS(see

edit flag offensive delete link more


So what needs to go in the custom CMake file for Boost? What properties are being ignored by ament's dependency mechanism?

DanRose gravatar image DanRose  ( 2019-09-07 09:12:35 -0600 )edit

Since ROS 2 tried to use newer C++ features instead of Boost where possible I don't have an example at hand. A similar case exporting TinyXML2 instead of Boost can be found here: and

Dirk Thomas gravatar image Dirk Thomas  ( 2019-09-08 01:09:07 -0600 )edit

Thanks! I wrote up an issue here:

It would be nice to have a solution in ament rather than coding up a wrapper for each component-based CMake package. I definitely don't have the knowledge right now to make a PR myself.

DanRose gravatar image DanRose  ( 2019-09-08 03:02:09 -0600 )edit

is finally the idea of ament_export_dependency_with_components something to explore? I imagine something like: ament_export_dependency_with_components(Boost COMPONENTS thread)

Pablo Iñigo Blasco gravatar image Pablo Iñigo Blasco  ( 2020-09-29 12:27:02 -0600 )edit
Dirk Thomas gravatar image Dirk Thomas  ( 2020-09-29 12:37:31 -0600 )edit
felixf4xu gravatar image felixf4xu  ( 2023-07-21 02:08:20 -0600 )edit

answered 2020-10-06 12:09:41 -0600

mjm522 gravatar image

I had the same issue trying to port a package from ROS1 to ROS2. After some research, I figured out following way helps to link the Boost libraries correctly.

find_package(Boost REQUIRED COMPONENTS 


edit flag offensive delete link more

Question Tools



Asked: 2019-08-19 18:47:39 -0600

Seen: 2,469 times

Last updated: Oct 06 '20