c++ - 对 boost::system 的 undefined reference

标签 c++ boost cmake ros undefined-reference

我正在尝试使用 Cmake 编译一个简单的 ROS/cpp 项目,但我在 boost 库时遇到了问题...

我使用的 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() »

.......

最佳答案

因为你没有 Boost 1.66,你需要链接到 boost::system:

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

关于c++ - 对 boost::system 的 undefined reference ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54647889/

相关文章:

c++ - 通过 boost 和 c++ 进行 smtp 身份验证

c++ - 如何将派生类的 shared_ptr vector 转换为基类的 shared_ptr vector

c++ - gmock SetArgReferee : Set a non-copyable non-moveable object

boost - Boost.Hana 中的 BOOST_FUSION_ADAPT_ASSOC 相当于什么?

cmake - 具有多个源文件的 ESP-IDF 项目

c++ - 在哪里定义/声明比较运算符的重载为库中的非成员函数?

c++ - 构造函数后面的宏。这是什么意思?

c++ - `BOOST_ENDIAN_BIG_BYTE` 和 `BOOST_ENDIAN_BIG_WORD` 有什么区别?

c++ - CMakeLists 不会包含 Boost header

c++ - 如何将 opendnp3 添加为静态 C++ 库