栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

ubuntu展示点云使用boost::this

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

ubuntu展示点云使用boost::this

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' 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  

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.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动态库

编译成功:

以上。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/733672.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号