ubuntu展示点云使用boost::this_thread报错

31 篇文章 3 订阅
6 篇文章 0 订阅

Ubuntu展示点云使用boost::this_thread报错

Ubuntu使用boost::this_thread展示点云

	boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer(new pcl::visualization::PCLVisualizer("3D Viewer"));
    viewer->setBackgroundColor(180, 180, 180);
    viewer->addCoordinateSystem(1.0);
    viewer->initCameraParameters();
    pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZI> color_right(cloud_right, 255, 0, 0);
    viewer->addPointCloud<pcl::PointXYZI>(cloud_right, color_right, "cloud_right");
    pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZI> color_left(cloud_left, 0, 0, 255);
    viewer->addPointCloud<pcl::PointXYZI>(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' failed
make[2]: *** [CMakeFiles/Cluster_ExtractCentrepoint.dir/Cluster_ExtractCentrepoint.cc.o] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/Cluster_ExtractCentrepoint.dir/all' failed
make[1]: *** [CMakeFiles/Cluster_ExtractCentrepoint.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

头文件中增加boost的头文件

#include <boost/thread/thread.hpp> 

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 status
CMakeFiles/Cluster_ExtractCentrepoint.dir/build.make:197: recipe for target 'Cluster_ExtractCentrepoint' failed
make[2]: *** [Cluster_ExtractCentrepoint] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/Cluster_ExtractCentrepoint.dir/all' failed
make[1]: *** [CMakeFiles/Cluster_ExtractCentrepoint.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [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.1IF (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动态库
在这里插入图片描述

编译成功:

在这里插入图片描述以上。

  • 3
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值