Ubuntu使用boost::this_thread展示点云
boost::shared_ptr
头文件没有加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动态库
以上。