1

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() »

.......

  • You may need to add -lboost_system compiler flag for boost libraries see: https://stackoverflow.com/questions/9723793/undefined-reference-to-boostsystemsystem-category-when-compiling – Ryan Christensen Feb 12 '19 at 10:30

1 Answers1

1

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})
Matthieu Brucher
  • 21,634
  • 7
  • 38
  • 62
  • Thank you for the answer, I don't know if it is the same problem but I have this error now ... /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o : Dans la fonction « _start » : (.text+0x20) : référence indéfinie vers « main » collect2: error: ld returned 1 exit status CMakeFiles/main.dir/build.make:95: recipe for target 'main' failed make[2]: *** [main] Error 1 CMakeFiles/Makefile2:611: recipe for target 'CMakeFiles/main.dir/all' failed make[1]: *** [CMakeFiles/main.dir/all] Error 2 Makefile:140: recipe for target 'all' failed make: *** [all] Error 2 – Karl Montalban Feb 12 '19 at 10:33
  • Of course, you need to have a `main` function for an executable (and read the error messages, they are in clear French after all). – Matthieu Brucher Feb 12 '19 at 10:34
  • I understand but I do have a main.cpp and a main() function inside. – Karl Montalban Feb 12 '19 at 10:37
  • Obviously not. The error is very explicit about the fact that you **don't** have a main function. – Matthieu Brucher Feb 12 '19 at 10:39
  • Does a simple main `int main(){}` work? Without any include headers, without anything? – Matthieu Brucher Feb 12 '19 at 11:13