对boost :: system的未定义引用

时间:2019-02-12 10:25:35

标签: c++ boost cmake ros undefined-reference

我正在尝试使用Cmake编译一个简单的ROS / cpp项目,但在提升库文件方面却遇到了问题...

我使用的Cmake:

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)

我的cmake命令显示找到了Boost:

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

我的main.cpp:

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

这是我的错误:

........

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

.......

1 个答案:

答案 0 :(得分:0)

由于您没有Boost 1.66,因此需要链接到boost :: system:

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