Search code examples
c++boostcmakerosundefined-reference

Undefined reference to boost::system


I'm trying to compile a simple ROS / cpp project with Cmake but I have a problem boost librairies...

The Cmake I use :

cmake_minimum_required(VERSION 2.8.3)

project(laserprojection)

#add_definitions(-DBOOST_ERROR_CODE_HEADER_ONLY)

find_package(catkin REQUIRED COMPONENTS 
  roscpp
  rospy
  std_msgs
  geometry_msgs
  message_generation
)

find_package(Boost 1.65.0 REQUIRED COMPONENTS system thread filesystem)
find_package(Eigen3 REQUIRED)

include_directories(${catkin_INCLUDE_DIRS} ${EIGEN3_INCLUDE_DIR} ${Boost_INCLUDE_DIRS})

add_executable(main main.cpp)

My cmake command shows that Boost is found :

Boost version: 1.65.1
Found the following Boost libraries:
system
thread
filesystem
chrono
date_time
atomic

My main.cpp :

#include <ros/ros.h>
#include <tf/transform_listener.h>
#include <laser_geometry/laser_geometry.h>

This is my Error :

........

main.cpp:(.text+0x63) : référence indéfinie vers « boost::system::generic_category() »
main.cpp:(.text+0x6f) : référence indéfinie vers « boost::system::generic_category() »
main.cpp:(.text+0x7b) : référence indéfinie vers « boost::system::system_category() »

.......


Solution

  • As you don't have Boost 1.66, you need to link against boost::system:

    add_executable(main main.cpp)
    target_link_libraries(main ${Boost_SYSTEM_LIBRARY})