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

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/libboost_thread.so.1.65.1: 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)
project(open_karto)
find_package(Boost REQUIRED COMPONENTS thread)
include_directories(include)
add_library(karto SHARED src/Karto.cpp src/Mapper.cpp)
ament_target_dependencies(karto Boost)
ament_export_include_directories(include)
ament_export_libraries(karto)
ament_export_dependencies(Boost)

From the consuming package CMakeLists.txt:

ament_target_dependencies(slam_karto
  open_karto
  )

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)
ament_target_dependencies(slam_karto
  open_karto
  Boost
  )
edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
1

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

Dirk Thomas gravatar image

The API docs of the ament_export_dependenciesfunctions (https://github.com/ament/ament_cmake/...) 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 https://github.com/ament/ament_cmake/...).

edit flag offensive delete link more

Comments

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
2

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: https://github.com/ros/pluginlib/blob... and https://github.com/ros/pluginlib/blob...

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

Thanks! I wrote up an issue here: https://github.com/ament/ament_cmake/...

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
1

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 
  system 
  thread 
  program_options
)

target_link_libraries(myPackage
                      ${Boost_LIBRARIES})

ament_target_dependencies(myPackage 
                          rclcpp
                          geometry_msgs)
edit flag offensive delete link more

Question Tools

3 followers

Stats

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

Seen: 3,121 times

Last updated: Oct 06 '20