欢迎您访问365答案网,请分享给你的朋友!
生活常识 学习资料

ubuntu展示点云使用boost::this

时间:2023-06-27
Ubuntu展示点云使用boost::this_thread报错

Ubuntu使用boost::this_thread展示点云

boost::shared_ptr viewer(new pcl::visualization::PCLVisualizer("3D Viewer")); viewer->setBackgroundColor(180, 180, 180); viewer->addCoordinateSystem(1.0); viewer->initCameraParameters(); pcl::visualization::PointCloudColorHandlerCustom color_right(cloud_right, 255, 0, 0); viewer->addPointCloud(cloud_right, color_right, "cloud_right"); pcl::visualization::PointCloudColorHandlerCustom color_left(cloud_left, 0, 0, 255); viewer->addPointCloud(cloud_left, color_left, "cloud_left"); while (!viewer->wasStopped()) { viewer->spinOnce(100); boost::this_thread::sleep (boost::posix_time::microseconds (100000)); //boost::thread::sleep(boost::get_system_time() + boost::posix_time::seconds(5)); }return;

头文件没有加boost的任何头文件,make时报错boost::this_thread’ has not been declared:

/home/qiancj/Desktop/ShareFolder/5Codes/Cluster_ExtractCentrepoint/Cluster_ExtractCentrepoint.cc: In function ‘int main(int, char**)’:/home/qiancj/Desktop/ShareFolder/5Codes/Cluster_ExtractCentrepoint/Cluster_ExtractCentrepoint.cc:277:16: error: ‘boost::this_thread’ has not been declared boost::this_thread::sleep(boost::posix_time::microseconds(100000)); ^~~~~~~~~~~CMakeFiles/Cluster_ExtractCentrepoint.dir/build.make:62: recipe for target 'CMakeFiles/Cluster_ExtractCentrepoint.dir/Cluster_ExtractCentrepoint.cc.o' failedmake[2]: *** [CMakeFiles/Cluster_ExtractCentrepoint.dir/Cluster_ExtractCentrepoint.cc.o] Error 1CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/Cluster_ExtractCentrepoint.dir/all' failedmake[1]: *** [CMakeFiles/Cluster_ExtractCentrepoint.dir/all] Error 2Makefile:83: recipe for target 'all' failedmake: *** [all] Error 2

头文件中增加boost的头文件

#include

make时报错undefined reference to boost::this_thread::hidden::sleep_until(timespec const&):

CMakeFiles/Cluster_ExtractCentrepoint.dir/Cluster_ExtractCentrepoint.cc.o: In function `boost::this_thread::sleep(boost::posix_time::ptime const&)':Cluster_ExtractCentrepoint.cc:(.text._ZN5boost11this_thread5sleepERKNS_10posix_time5ptimeE[_ZN5boost11this_thread5sleepERKNS_10posix_time5ptimeE]+0x37): undefined reference to `boost::this_thread::hidden::sleep_until(timespec const&)'collect2: error: ld returned 1 exit statusCMakeFiles/Cluster_ExtractCentrepoint.dir/build.make:197: recipe for target 'Cluster_ExtractCentrepoint' failedmake[2]: *** [Cluster_ExtractCentrepoint] Error 1CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/Cluster_ExtractCentrepoint.dir/all' failedmake[1]: *** [CMakeFiles/Cluster_ExtractCentrepoint.dir/all] Error 2Makefile:83: recipe for target 'all' failedmake: *** [all] Error 2

Method 1

需要在cmake之后,修改生成的项目.dir目录下link.txt文件:

在文件最后增加

-lboost_thread

Method 2

方法1就是添加了boost_thread的链接,所以直接在CmakeLists.txt文件中添加即可

find_package(Boost 1.65.1 REQUIRED COMPonENTS thread) # 我的boost版本是1.65.1的IF (Boost_FOUND) INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIR}) Message(STATUS, "PRINT BOOST: ${Boost_INCLUDE_DIR}") Message(STATUS, "PRINT BOOST: ${Boost_THREAD_LIBRARY}") ADD_DEFINITIONS( "-DHAS_BOOST" )ENDIF()target_link_libraries (ProjectName ${Boost_THREAD_LIBRARY})

cmake之后,再打开link.txt文件,发现新增了/usr/lib/x86_64-linux-gnu/libboost_thread.so动态库

编译成功:

以上。

Copyright © 2016-2020 www.365daan.com All Rights Reserved. 365答案网 版权所有 备案号:

部分内容来自互联网,版权归原作者所有,如有冒犯请联系我们,我们将在三个工作时内妥善处理。