C++ boost库----share_from_this类的作用和实现原理

本文探讨了在使用Boost库时,如何通过使类继承自enable_share_from_this来正确使用shared_ptr管理对象,并解释了share_from_this()方法的工作原理。

原文链接:

使用boost库时,经常会看到如下的类

class A:public enable_share_from_this<A>

在什么情况下要使类A继承enable_share_from_this?

使用场合:当类A被share_ptr管理,且在类A的成员函数里需要把当前类对象作为参数传给其他函数时,就需要传递一个指向自身的share_ptr。

我们就使类A继承enable_share_from_this,然后通过其成员函数share_from_this()返回当指向自身的share_ptr。

以上有2个疑惑:

1.把当前类对象作为参数传给其他函数时,为什么要传递share_ptr呢?直接传递this指针不可以吗?

一个裸指针传递给调用者,谁也不知道调用者会干什么?假如调用者delete了该对象,而share_tr此时还指向该对象。

2.这样传递share_ptr可以吗?share_ptr<this>

这样会造成2个非共享的share_ptr指向一个对象,最后造成2次析构该对象。

boost官方文档中一个非常典型的例子:http://www.boost.org/doc/libs/1_55_0/doc/html/boost_asio/tutorial/tutdaytime3/src.html

部分代码:

复制代码
 1 class tcp_connection
 2   : public boost::enable_shared_from_this<tcp_connection>
 3 {
 4 public:
 5   typedef boost::shared_ptr<tcp_connection> pointer;
 6 
 7   static pointer create(boost::asio::io_service& io_service)
 8   {
 9     return pointer(new tcp_connection(io_service));
10   }
11 
12   tcp::socket& socket()
13   {
14     return socket_;
15   }
16 
17   void start()
18   {
19     message_ = make_daytime_string();
20 
21     boost::asio::async_write(socket_, boost::asio::buffer(message_),
22         boost::bind(&tcp_connection::handle_write, shared_from_this(),
23           boost::asio::placeholders::error,
24           boost::asio::placeholders::bytes_transferred));
25   }
26 
27 private:
28   tcp_connection(boost::asio::io_service& io_service)
29     : socket_(io_service)
30   {
31   }
32 
33   void handle_write(const boost::system::error_code& /*error*/,
34       size_t /*bytes_transferred*/)
35   {
36   }
37 
38   tcp::socket socket_;
39   std::string message_;
40 };
复制代码

类tcp_connection继承enable_share_from_this,在22行里,它的成员函数start(),通过share_from_this返回指向自身的share_ptr。

实现原理:

share_from_this()是如何返回指向该对象的share_ptr的?显然它不能直接return share_ptr<this>。因为它返回的share_ptr必须和管理该对象的share_ptr是共享的,也就是说返回的share_ptr的引用计数和管理该对象的share_ptr的引用计数是相同的。其实enable_share_from_this就存储了管理该对象的share_ptr的引用计数,通过weak_ptr来实现。在enable_share_from_this,里有一个成员weak_this_。

但现在的问题是:何时初始化这个 weak_ptr ?因为类对象生成时还没有生成相应的用来管理这个对象的 shared_ptr 。其实是通过share_ptr的构造函数中初始化这个weak_ptr的.

shared_ptr 定义了如下构造函数:
1  template<class Y>
2 explicit shared_ptr( Y * p ): px( p ), pn() // Y must be complete
3 {
4   boost::detail::sp_pointer_construct( this, p, pn );
5 }
里面调用了  boost::detail::sp_pointer_construct 
复制代码
1 template< class T, class Y > inline void sp_pointer_construct( boost::shared_ptr< T > * ppx, Y * p, boost::detail::shared_count & pn )
2 {
3    boost::detail::shared_count( p ).swap( pn );
4    boost::detail::sp_enable_shared_from_this( ppx, p, p );
5 }
复制代码
 里面又调用了boost::detail::sp_enable_shared_from_this
 
share_ptr有2个该重载函数
复制代码
1 template< class X, class Y, class T > inline void sp_enable_shared_from_this( boost::shared_ptr<X> const * ppx, Y const * py, boost::enable_shared_from_this< T > const * pe )
2 {
3   if( pe != 0 )
4  {
5    pe->_internal_accept_owner( ppx, const_cast< Y* >( py ) );
6  }
7 }
复制代码
1 inline void sp_enable_shared_from_this( ... )
2 {
3 }

由于我们的类是继承enable_share_from_this,所以调用的是前者

里面又调用了 enable_shared_from_this 的 _internal_accept_owner :
复制代码
template<class X, class Y> void _internal_accept_owner( shared_ptr<X> const * ppx, Y * py ) const
{
  if( weak_this_.expired() )
  {
    weak_this_ = shared_ptr<T>( *ppx, py );
  }
}
复制代码

最后,在这里对enable_shared_from_this 的成员 weak_this_ 进行拷贝赋值,使得整个 weak_ptr 作为类对象shared_ptr 的一个观察者。当调用share_from_this()时,就可以从这个 weak_ptr 来生成了,且引用计数是相同的。

复制代码
1 shared_ptr<T const> shared_from_this() const
2 {
3  shared_ptr<T const> p( weak_this_ );
4  BOOST_ASSERT( p.get() == this );
5  return p;
6 }

Windows PowerShell 版权所有(C) Microsoft Corporation。保留所有权利。 安装最新的 PowerShell,了解新功能改进!https://aka.ms/PSWindows 加载个人及系统配置文件用了 1435 毫秒。 (base) PS Microsoft.PowerShell.Core\FileSystem::\\wsl.localhost\Ubuntu\home\lixing\catkin_ws> wsl wsl: Failed to translate 'G:\mingw64\bin' wsl: Failed to translate 'G:\java\bin' wsl: Failed to translate 'G:\java\jre\bin' wsl: Failed to translate 'G:\CTEX\UserData\miktex\bin' wsl: Failed to translate 'G:\CTEX\MiKTeX\miktex\bin' wsl: Failed to translate 'G:\CTEX\CTeX\ctex\bin' wsl: Failed to translate 'G:\CTEX\CTeX\cct\bin' wsl: Failed to translate 'G:\CTEX\CTeX\ty\bin' wsl: Failed to translate 'G:\CTEX\Ghostscript\gs9.05\bin' wsl: Failed to translate 'G:\CTEX\GSview\gsview' lixing@DESKTOP-2PJK7EV:~/catkin_ws$ git clone https://github.com/emNavi/Fast-LIO2.git Cloning into 'Fast-LIO2'... remote: Enumerating objects: 1112, done. remote: Counting objects: 100% (53/53), done. remote: Compressing objects: 100% (44/44), done. remote: Total 1112 (delta 15), reused 28 (delta 9), pack-reused 1059 (from 1) Receiving objects: 100% (1112/1112), 162.66 MiB | 8.33 MiB/s, done. Resolving deltas: 100% (199/199), done. lixing@DESKTOP-2PJK7EV:~/catkin_ws$ cd Fast-LIO2 lixing@DESKTOP-2PJK7EV:~/catkin_ws/Fast-LIO2$ catkin_make Base path: /home/lixing/catkin_ws/Fast-LIO2 Source space: /home/lixing/catkin_ws/Fast-LIO2/src Build space: /home/lixing/catkin_ws/Fast-LIO2/build Devel space: /home/lixing/catkin_ws/Fast-LIO2/devel Install space: /home/lixing/catkin_ws/Fast-LIO2/install Creating symlink "/home/lixing/catkin_ws/Fast-LIO2/src/CMakeLists.txt" pointing to "/opt/ros/noetic/share/catkin/cmake/toplevel.cmake" #### #### Running command: "cmake /home/lixing/catkin_ws/Fast-LIO2/src -DCATKIN_DEVEL_PREFIX=/home/lixing/catkin_ws/Fast-LIO2/devel -DCMAKE_INSTALL_PREFIX=/home/lixing/catkin_ws/Fast-LIO2/install -G Unix Makefiles" in "/home/lixing/catkin_ws/Fast-LIO2/build" #### -- The C compiler identification is GNU 9.4.0 -- The CXX compiler identification is GNU 9.4.0 -- Check for working C compiler: /usr/bin/cc -- Check for working C compiler: /usr/bin/cc -- works -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Detecting C compile features -- Detecting C compile features - done -- Check for working CXX compiler: /usr/bin/c++ -- Check for working CXX compiler: /usr/bin/c++ -- works -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Detecting CXX compile features -- Detecting CXX compile features - done -- Using CATKIN_DEVEL_PREFIX: /home/lixing/catkin_ws/Fast-LIO2/devel -- Using CMAKE_PREFIX_PATH: /opt/ros/noetic -- This workspace overlays: /opt/ros/noetic -- Found PythonInterp: /usr/bin/python3 (found suitable version "3.8.10", minimum required is "3") -- Using PYTHON_EXECUTABLE: /usr/bin/python3 -- Using Debian Python package layout -- Found PY_em: /usr/lib/python3/dist-packages/em.py -- Using empy: /usr/lib/python3/dist-packages/em.py -- Using CATKIN_ENABLE_TESTING: ON -- Call enable_testing() -- Using CATKIN_TEST_RESULTS_DIR: /home/lixing/catkin_ws/Fast-LIO2/build/test_results -- Forcing gtest/gmock from source, though one was otherwise available. -- Found gtest sources under '/usr/src/googletest': gtests will be built -- Found gmock sources under '/usr/src/googletest': gmock will be built -- Found PythonInterp: /usr/bin/python3 (found version "3.8.10") -- Looking for pthread.h -- Looking for pthread.h - found -- Performing Test CMAKE_HAVE_LIBC_PTHREAD -- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed -- Looking for pthread_create in pthreads -- Looking for pthread_create in pthreads - not found -- Looking for pthread_create in pthread -- Looking for pthread_create in pthread - found -- Found Threads: TRUE -- Using Python nosetests: /usr/bin/nosetests3 -- catkin 0.8.12 -- BUILD_SHARED_LIBS is on -- BUILD_SHARED_LIBS is on -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- ~~ traversing 24 packages in topological order: -- ~~ - quadrotor_msgs -- ~~ - cmake_utils -- ~~ - map_generator -- ~~ - plan_env -- ~~ - path_searching -- ~~ - poscmd_2_odom -- ~~ - pose_utils -- ~~ - drone_detect -- ~~ - livox2pointcloud -- ~~ - aloam_velodyne -- ~~ - odom_visualization -- ~~ - fast_lio -- ~~ - local_sensing_node -- ~~ - mockamap -- ~~ - so3_control -- ~~ - multi_map_server -- ~~ - traj_utils -- ~~ - bspline_opt -- ~~ - ego_planner -- ~~ - rosmsg_tcp_bridge -- ~~ - uav_utils -- ~~ - so3_quadrotor_simulator -- ~~ - rviz_plugins -- ~~ - waypoint_generator -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- +++ processing catkin package: 'quadrotor_msgs' -- ==> add_subdirectory(ego-planner-swarm-v1/src/uav_simulator/Utils/quadrotor_msgs) -- Using these message generators: gencpp;geneus;genlisp;gennodejs;genpy -- quadrotor_msgs: 13 messages, 0 services -- Found Eigen3: /usr/local/include/eigen3 (Required is at least version "2.91.0") -- +++ processing catkin package: 'cmake_utils' -- ==> add_subdirectory(ego-planner-swarm-v1/src/uav_simulator/Utils/cmake_utils) -- +++ processing catkin package: 'map_generator' -- ==> add_subdirectory(ego-planner-swarm-v1/src/uav_simulator/map_generator) -- Checking for module 'eigen3' -- Found eigen3, version 3.3.7 -- Found Eigen: /usr/include/eigen3 (Required is at least version "3.1") -- Eigen found (include: /usr/include/eigen3, version: 3.3.7) -- Found Boost: /usr/include (found suitable version "1.71.0", minimum required is "1.55.0") found components: system filesystem date_time iostreams regex -- Checking for module 'flann' -- Found flann, version 1.9.1 -- Found FLANN: /usr/lib/x86_64-linux-gnu/libflann_cpp.so -- The imported target "vtkParseOGLExt" references the file "/usr/bin/vtkParseOGLExt-7.1" but this file does not exist. Possible reasons include: * The file was deleted, renamed, or moved to another location. * An install or uninstall procedure did not complete successfully. * The installation package was faulty and contained "/usr/lib/cmake/vtk-7.1/VTKTargets.cmake" but not all the files it references. -- The imported target "vtkRenderingPythonTkWidgets" references the file "/usr/lib/x86_64-linux-gnu/libvtkRenderingPythonTkWidgets.so" but this file does not exist. Possible reasons include: * The file was deleted, renamed, or moved to another location. * An install or uninstall procedure did not complete successfully. * The installation package was faulty and contained "/usr/lib/cmake/vtk-7.1/VTKTargets.cmake" but not all the files it references. -- The imported target "vtk" references the file "/usr/bin/vtk" but this file does not exist. Possible reasons include: * The file was deleted, renamed, or moved to another location. * An install or uninstall procedure did not complete successfully. * The installation package was faulty and contained "/usr/lib/cmake/vtk-7.1/VTKTargets.cmake" but not all the files it references. -- The imported target "pvtk" references the file "/usr/bin/pvtk" but this file does not exist. Possible reasons include: * The file was deleted, renamed, or moved to another location. * An install or uninstall procedure did not complete successfully. * The installation package was faulty and contained "/usr/lib/cmake/vtk-7.1/VTKTargets.cmake" but not all the files it references. -- Checking for module 'libusb-1.0' -- Found libusb-1.0, version 1.0.23 -- Found USB_10: /usr/lib/x86_64-linux-gnu/libusb-1.0.so -- Found OpenNI: /usr/lib/libOpenNI.so -- OpenNI found (include: /usr/include/ni, lib: /usr/lib/libOpenNI.so) -- Found OpenNI2: /usr/lib/libOpenNI2.so -- OpenNI2 found (include: /usr/include/openni2, lib: /usr/lib/libOpenNI2.so) ** WARNING ** io features related to pcap will be disabled ** WARNING ** io features related to png will be disabled -- Found libusb-1.0: /usr/include ** WARNING ** io features related to libusb-1.0 will be disabled -- OpenNI found (include: /usr/include/ni, lib: /usr/lib/libOpenNI.so) -- OpenNI2 found (include: /usr/include/openni2, lib: /usr/lib/libOpenNI2.so) -- Found Qhull: optimized;/usr/lib/x86_64-linux-gnu/libqhull.so;debug;/usr/lib/x86_64-linux-gnu/libqhull.so -- QHULL found (include: /usr/include, lib: optimized;/usr/lib/x86_64-linux-gnu/libqhull.so;debug;/usr/lib/x86_64-linux-gnu/libqhull.so) -- OpenNI found (include: /usr/include/ni, lib: /usr/lib/libOpenNI.so) -- looking for PCL_COMMON -- Found PCL_COMMON: /usr/lib/x86_64-linux-gnu/libpcl_common.so -- looking for PCL_KDTREE -- Found PCL_KDTREE: /usr/lib/x86_64-linux-gnu/libpcl_kdtree.so -- looking for PCL_OCTREE -- Found PCL_OCTREE: /usr/lib/x86_64-linux-gnu/libpcl_octree.so -- looking for PCL_SEARCH -- Found PCL_SEARCH: /usr/lib/x86_64-linux-gnu/libpcl_search.so -- looking for PCL_SAMPLE_CONSENSUS -- Found PCL_SAMPLE_CONSENSUS: /usr/lib/x86_64-linux-gnu/libpcl_sample_consensus.so -- looking for PCL_FILTERS -- Found PCL_FILTERS: /usr/lib/x86_64-linux-gnu/libpcl_filters.so -- looking for PCL_2D -- Found PCL_2D: /usr/include/pcl-1.10 -- looking for PCL_GEOMETRY -- Found PCL_GEOMETRY: /usr/include/pcl-1.10 -- looking for PCL_IO -- Found PCL_IO: /usr/lib/x86_64-linux-gnu/libpcl_io.so -- looking for PCL_FEATURES -- Found PCL_FEATURES: /usr/lib/x86_64-linux-gnu/libpcl_features.so -- looking for PCL_ML -- Found PCL_ML: /usr/lib/x86_64-linux-gnu/libpcl_ml.so -- looking for PCL_SEGMENTATION -- Found PCL_SEGMENTATION: /usr/lib/x86_64-linux-gnu/libpcl_segmentation.so -- looking for PCL_VISUALIZATION -- Found PCL_VISUALIZATION: /usr/lib/x86_64-linux-gnu/libpcl_visualization.so -- looking for PCL_SURFACE -- Found PCL_SURFACE: /usr/lib/x86_64-linux-gnu/libpcl_surface.so -- looking for PCL_REGISTRATION -- Found PCL_REGISTRATION: /usr/lib/x86_64-linux-gnu/libpcl_registration.so -- looking for PCL_KEYPOINTS -- Found PCL_KEYPOINTS: /usr/lib/x86_64-linux-gnu/libpcl_keypoints.so -- looking for PCL_TRACKING -- Found PCL_TRACKING: /usr/lib/x86_64-linux-gnu/libpcl_tracking.so -- looking for PCL_RECOGNITION -- Found PCL_RECOGNITION: /usr/lib/x86_64-linux-gnu/libpcl_recognition.so -- looking for PCL_STEREO -- Found PCL_STEREO: /usr/lib/x86_64-linux-gnu/libpcl_stereo.so -- looking for PCL_APPS -- Found PCL_APPS: /usr/lib/x86_64-linux-gnu/libpcl_apps.so -- looking for PCL_IN_HAND_SCANNER -- Found PCL_IN_HAND_SCANNER: /usr/include/pcl-1.10 -- looking for PCL_POINT_CLOUD_EDITOR -- Found PCL_POINT_CLOUD_EDITOR: /usr/include/pcl-1.10 -- looking for PCL_OUTOFCORE -- Found PCL_OUTOFCORE: /usr/lib/x86_64-linux-gnu/libpcl_outofcore.so -- looking for PCL_PEOPLE -- Found PCL_PEOPLE: /usr/lib/x86_64-linux-gnu/libpcl_people.so -- Found PCL: pcl_common;pcl_kdtree;pcl_octree;pcl_search;pcl_sample_consensus;pcl_filters;pcl_io;pcl_features;pcl_ml;pcl_segmentation;pcl_visualization;pcl_surface;pcl_registration;pcl_keypoints;pcl_tracking;pcl_recognition;pcl_stereo;pcl_apps;pcl_outofcore;pcl_people;/usr/lib/x86_64-linux-gnu/libboost_system.so;/usr/lib/x86_64-linux-gnu/libboost_filesystem.so;/usr/lib/x86_64-linux-gnu/libboost_date_time.so;/usr/lib/x86_64-linux-gnu/libboost_iostreams.so;/usr/lib/x86_64-linux-gnu/libboost_regex.so;optimized;/usr/lib/x86_64-linux-gnu/libqhull.so;debug;/usr/lib/x86_64-linux-gnu/libqhull.so;/usr/lib/libOpenNI.so;/usr/lib/libOpenNI2.so;vtkChartsCore;vtkCommonColor;vtkCommonCore;vtksys;vtkCommonDataModel;vtkCommonMath;vtkCommonMisc;vtkCommonSystem;vtkCommonTransforms;vtkCommonExecutionModel;vtkFiltersGeneral;vtkCommonComputationalGeometry;vtkFiltersCore;vtkInfovisCore;vtkFiltersExtraction;vtkFiltersStatistics;vtkImagingFourier;vtkImagingCore;vtkalglib;vtkRenderingContext2D;vtkRenderingCore;vtkFiltersGeometry;vtkFiltersSources;vtkRenderingFreeType;/usr/lib/x86_64-linux-gnu/libfreetype.so;/usr/lib/x86_64-linux-gnu/libz.so;vtkFiltersModeling;vtkImagingSources;vtkInteractionStyle;vtkInteractionWidgets;vtkFiltersHybrid;vtkImagingColor;vtkImagingGeneral;vtkImagingHybrid;vtkIOImage;vtkDICOMParser;vtkmetaio;/usr/lib/x86_64-linux-gnu/libjpeg.so;/usr/lib/x86_64-linux-gnu/libpng.so;/usr/lib/x86_64-linux-gnu/libtiff.so;vtkRenderingAnnotation;vtkRenderingVolume;vtkIOXML;vtkIOCore;vtkIOXMLParser;/usr/lib/x86_64-linux-gnu/libexpat.so;vtkIOGeometry;vtkIOLegacy;vtkIOPLY;vtkRenderingLOD;vtkViewsContext2D;vtkViewsCore;vtkRenderingContextOpenGL2;vtkRenderingOpenGL2;FLANN::FLANN -- +++ processing catkin package: 'plan_env' -- ==> add_subdirectory(ego-planner-swarm-v1/src/planner/plan_env) -- Found OpenCV: /usr (found version "4.2.0") -- Eigen found (include: /usr/include/eigen3, version: 3.3.7) -- The imported target "vtkParseOGLExt" references the file "/usr/bin/vtkParseOGLExt-7.1" but this file does not exist. Possible reasons include: * The file was deleted, renamed, or moved to another location. * An install or uninstall procedure did not complete successfully. * The installation package was faulty and contained "/usr/lib/cmake/vtk-7.1/VTKTargets.cmake" but not all the files it references. -- The imported target "vtkRenderingPythonTkWidgets" references the file "/usr/lib/x86_64-linux-gnu/libvtkRenderingPythonTkWidgets.so" but this file does not exist. Possible reasons include: * The file was deleted, renamed, or moved to another location. * An install or uninstall procedure did not complete successfully. * The installation package was faulty and contained "/usr/lib/cmake/vtk-7.1/VTKTargets.cmake" but not all the files it references. -- The imported target "vtk" references the file "/usr/bin/vtk" but this file does not exist. Possible reasons include: * The file was deleted, renamed, or moved to another location. * An install or uninstall procedure did not complete successfully. * The installation package was faulty and contained "/usr/lib/cmake/vtk-7.1/VTKTargets.cmake" but not all the files it references. -- The imported target "pvtk" references the file "/usr/bin/pvtk" but this file does not exist. Possible reasons include: * The file was deleted, renamed, or moved to another location. * An install or uninstall procedure did not complete successfully. * The installation package was faulty and contained "/usr/lib/cmake/vtk-7.1/VTKTargets.cmake" but not all the files it references. -- OpenNI found (include: /usr/include/ni, lib: /usr/lib/libOpenNI.so) -- OpenNI2 found (include: /usr/include/openni2, lib: /usr/lib/libOpenNI2.so) ** WARNING ** io features related to pcap will be disabled ** WARNING ** io features related to png will be disabled ** WARNING ** io features related to libusb-1.0 will be disabled -- OpenNI found (include: /usr/include/ni, lib: /usr/lib/libOpenNI.so) -- OpenNI2 found (include: /usr/include/openni2, lib: /usr/lib/libOpenNI2.so) -- QHULL found (include: /usr/include, lib: optimized;/usr/lib/x86_64-linux-gnu/libqhull.so;debug;/usr/lib/x86_64-linux-gnu/libqhull.so) -- OpenNI found (include: /usr/include/ni, lib: /usr/lib/libOpenNI.so) -- looking for PCL_COMMON -- looking for PCL_KDTREE -- looking for PCL_OCTREE -- looking for PCL_SEARCH -- looking for PCL_SAMPLE_CONSENSUS -- looking for PCL_FILTERS -- looking for PCL_2D -- looking for PCL_GEOMETRY -- looking for PCL_IO -- looking for PCL_FEATURES -- looking for PCL_ML -- looking for PCL_SEGMENTATION -- looking for PCL_VISUALIZATION -- looking for PCL_SURFACE -- looking for PCL_REGISTRATION -- looking for PCL_KEYPOINTS -- looking for PCL_TRACKING -- looking for PCL_RECOGNITION -- looking for PCL_STEREO -- looking for PCL_APPS -- looking for PCL_IN_HAND_SCANNER -- looking for PCL_POINT_CLOUD_EDITOR -- looking for PCL_OUTOFCORE -- looking for PCL_PEOPLE -- Found PCL: pcl_common;pcl_kdtree;pcl_octree;pcl_search;pcl_sample_consensus;pcl_filters;pcl_io;pcl_features;pcl_ml;pcl_segmentation;pcl_visualization;pcl_surface;pcl_registration;pcl_keypoints;pcl_tracking;pcl_recognition;pcl_stereo;pcl_apps;pcl_outofcore;pcl_people;/usr/lib/x86_64-linux-gnu/libboost_system.so;/usr/lib/x86_64-linux-gnu/libboost_filesystem.so;/usr/lib/x86_64-linux-gnu/libboost_date_time.so;/usr/lib/x86_64-linux-gnu/libboost_iostreams.so;/usr/lib/x86_64-linux-gnu/libboost_regex.so;optimized;/usr/lib/x86_64-linux-gnu/libqhull.so;debug;/usr/lib/x86_64-linux-gnu/libqhull.so;/usr/lib/libOpenNI.so;/usr/lib/libOpenNI2.so;vtkChartsCore;vtkCommonColor;vtkCommonCore;vtksys;vtkCommonDataModel;vtkCommonMath;vtkCommonMisc;vtkCommonSystem;vtkCommonTransforms;vtkCommonExecutionModel;vtkFiltersGeneral;vtkCommonComputationalGeometry;vtkFiltersCore;vtkInfovisCore;vtkFiltersExtraction;vtkFiltersStatistics;vtkImagingFourier;vtkImagingCore;vtkalglib;vtkRenderingContext2D;vtkRenderingCore;vtkFiltersGeometry;vtkFiltersSources;vtkRenderingFreeType;/usr/lib/x86_64-linux-gnu/libfreetype.so;/usr/lib/x86_64-linux-gnu/libz.so;vtkFiltersModeling;vtkImagingSources;vtkInteractionStyle;vtkInteractionWidgets;vtkFiltersHybrid;vtkImagingColor;vtkImagingGeneral;vtkImagingHybrid;vtkIOImage;vtkDICOMParser;vtkmetaio;/usr/lib/x86_64-linux-gnu/libjpeg.so;/usr/lib/x86_64-linux-gnu/libpng.so;/usr/lib/x86_64-linux-gnu/libtiff.so;vtkRenderingAnnotation;vtkRenderingVolume;vtkIOXML;vtkIOCore;vtkIOXMLParser;/usr/lib/x86_64-linux-gnu/libexpat.so;vtkIOGeometry;vtkIOLegacy;vtkIOPLY;vtkRenderingLOD;vtkViewsContext2D;vtkViewsCore;vtkRenderingContextOpenGL2;vtkRenderingOpenGL2;FLANN::FLANN (Required is at least version "1.7") -- +++ processing catkin package: 'path_searching' -- ==> add_subdirectory(ego-planner-swarm-v1/src/planner/path_searching) -- Eigen found (include: /usr/include/eigen3, version: 3.3.7) -- The imported target "vtkParseOGLExt" references the file "/usr/bin/vtkParseOGLExt-7.1" but this file does not exist. Possible reasons include: * The file was deleted, renamed, or moved to another location. * An install or uninstall procedure did not complete successfully. * The installation package was faulty and contained "/usr/lib/cmake/vtk-7.1/VTKTargets.cmake" but not all the files it references. -- The imported target "vtkRenderingPythonTkWidgets" references the file "/usr/lib/x86_64-linux-gnu/libvtkRenderingPythonTkWidgets.so" but this file does not exist. Possible reasons include: * The file was deleted, renamed, or moved to another location. * An install or uninstall procedure did not complete successfully. * The installation package was faulty and contained "/usr/lib/cmake/vtk-7.1/VTKTargets.cmake" but not all the files it references. -- The imported target "vtk" references the file "/usr/bin/vtk" but this file does not exist. Possible reasons include: * The file was deleted, renamed, or moved to another location. * An install or uninstall procedure did not complete successfully. * The installation package was faulty and contained "/usr/lib/cmake/vtk-7.1/VTKTargets.cmake" but not all the files it references. -- The imported target "pvtk" references the file "/usr/bin/pvtk" but this file does not exist. Possible reasons include: * The file was deleted, renamed, or moved to another location. * An install or uninstall procedure did not complete successfully. * The installation package was faulty and contained "/usr/lib/cmake/vtk-7.1/VTKTargets.cmake" but not all the files it references. -- OpenNI found (include: /usr/include/ni, lib: /usr/lib/libOpenNI.so) -- OpenNI2 found (include: /usr/include/openni2, lib: /usr/lib/libOpenNI2.so) ** WARNING ** io features related to pcap will be disabled ** WARNING ** io features related to png will be disabled ** WARNING ** io features related to libusb-1.0 will be disabled -- OpenNI found (include: /usr/include/ni, lib: /usr/lib/libOpenNI.so) -- OpenNI2 found (include: /usr/include/openni2, lib: /usr/lib/libOpenNI2.so) -- QHULL found (include: /usr/include, lib: optimized;/usr/lib/x86_64-linux-gnu/libqhull.so;debug;/usr/lib/x86_64-linux-gnu/libqhull.so) -- OpenNI found (include: /usr/include/ni, lib: /usr/lib/libOpenNI.so) -- looking for PCL_COMMON -- looking for PCL_KDTREE -- looking for PCL_OCTREE -- looking for PCL_SEARCH -- looking for PCL_SAMPLE_CONSENSUS -- looking for PCL_FILTERS -- looking for PCL_2D -- looking for PCL_GEOMETRY -- looking for PCL_IO -- looking for PCL_FEATURES -- looking for PCL_ML -- looking for PCL_SEGMENTATION -- looking for PCL_VISUALIZATION -- looking for PCL_SURFACE -- looking for PCL_REGISTRATION -- looking for PCL_KEYPOINTS -- looking for PCL_TRACKING -- looking for PCL_RECOGNITION -- looking for PCL_STEREO -- looking for PCL_APPS -- looking for PCL_IN_HAND_SCANNER -- looking for PCL_POINT_CLOUD_EDITOR -- looking for PCL_OUTOFCORE -- looking for PCL_PEOPLE -- +++ processing catkin package: 'poscmd_2_odom' -- ==> add_subdirectory(ego-planner-swarm-v1/src/uav_simulator/fake_drone) -- Using these message generators: gencpp;geneus;genlisp;gennodejs;genpy -- +++ processing catkin package: 'pose_utils' -- ==> add_subdirectory(ego-planner-swarm-v1/src/uav_simulator/Utils/pose_utils) -- Found Armadillo: /usr/lib/libarmadillo.so (found version "9.800.4") -- +++ processing catkin package: 'drone_detect' -- ==> add_subdirectory(ego-planner-swarm-v1/src/planner/drone_detect) -- Found Boost: /usr/lib/x86_64-linux-gnu/cmake/Boost-1.71.0/BoostConfig.cmake (found version "1.71.0") CMake Warning at /opt/ros/noetic/share/catkin/cmake/catkin_package.cmake:166 (message): catkin_package() DEPENDS on 'Eigen' but neither 'Eigen_INCLUDE_DIRS' nor 'Eigen_LIBRARIES' is defined. Call Stack (most recent call first): /opt/ros/noetic/share/catkin/cmake/catkin_package.cmake:102 (_catkin_package) ego-planner-swarm-v1/src/planner/drone_detect/CMakeLists.txt:35 (catkin_package) -- +++ processing catkin package: 'livox2pointcloud' -- ==> add_subdirectory(livox2pointcloud) -- Could NOT find livox_ros_driver2 (missing: livox_ros_driver2_DIR) -- Could not find the required component 'livox_ros_driver2'. The following CMake error indicates that you either need to install the package with the same name or change your environment so that it can be found. CMake Error at /opt/ros/noetic/share/catkin/cmake/catkinConfig.cmake:83 (find_package): Could not find a package configuration file provided by "livox_ros_driver2" with any of the following names: livox_ros_driver2Config.cmake livox_ros_driver2-config.cmake Add the installation prefix of "livox_ros_driver2" to CMAKE_PREFIX_PATH or set "livox_ros_driver2_DIR" to a directory containing one of the above files. If "livox_ros_driver2" provides a separate development package or SDK, be sure it has been installed. Call Stack (most recent call first): livox2pointcloud/CMakeLists.txt:7 (find_package) -- Configuring incomplete, errors occurred! See also "/home/lixing/catkin_ws/Fast-LIO2/build/CMakeFiles/CMakeOutput.log". See also "/home/lixing/catkin_ws/Fast-LIO2/build/CMakeFiles/CMakeError.log". Invoking "cmake" failed lixing@DESKTOP-2PJK7EV:~/catkin_ws/Fast-LIO2$
最新发布
08-28
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值