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

How to edit target_link_libraries

asked 2013-05-06 22:29:43 -0500

modaei gravatar image

I'm trying to use boost package in Eclipse platform. In this line of code:

boost::this_thread::disable_interruption di;

Although boost-1.41.0-17 is installed and I have included boost/thread.hpp in the code, I receive the this error:

undefined reference to 'boost::this_thread::disable_interruption::disable_interruption()

I'm using CentOS 6 and gcc compiler. Anyone knows what's causing this problem?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2013-05-07 07:05:38 -0500

updated 2013-05-09 13:39:05 -0500

The boost::thread library is one of the boost libraries that is not contained only in header-files. Some of the boost::thread code also resides in binary library files that are installed on the system with the rest of the boost installation.

The error message you're getting indicates that the linker is unable to find the implementation code for the disable_interruption() method. It's probably located in the binary boost::thread library file, so you'll need to tell the linker to also link this library in with the rest of your project.

For ROS, this linking is typically configured in the package's CMakeLists.txt file. The exact call you'll use is different depending on whether you're using rosbuild or catkin:

  • For rosbuild, you can add rosbuild_link_boost(my_exe thread)
  • For catkin, you can add find_package(Boost REQUIRED COMPONENTS thread) followed by target_link_libraries(my_exe ${Boost_LIBRARIES})

If you're able to build your package from the command line, but are only having problems within Eclipse, then the problem may be related to your Eclipse configuration. See here for the recommended steps to configure and run Eclipse with ROS.

Edit: fix reference to ${Boost_LIBRARIES}, thanks to @"Dirk Thomas"

edit flag offensive delete link more


For CMake (catkin) the variable is ${Boost_LIBRARIES} - not the short name stated in the answer,

Dirk Thomas gravatar image Dirk Thomas  ( 2013-05-09 12:43:47 -0500 )edit

What if I only want to link thread lib?

ZiyangLI gravatar image ZiyangLI  ( 2015-08-02 11:01:59 -0500 )edit

Question Tools


Asked: 2013-05-06 22:29:43 -0500

Seen: 234 times

Last updated: May 09 '13