PCL之使用过程中遇到的坑、报错、解决方法

这篇博客准备记录PCL使用过程中遇到坑

1.编译报错:undefined reference to pcl::search::Search<pcl::PointXYZRGBA>::getName[ abi:cxx11]() const

undefined reference to `pcl::search::Search<pcl::PointXYZRGBA>::getName[abi:cxx11]() const'

解决方法

这类问题是由于pcl的版本导致,解决方案:安装更新的pcl;
或者添加下面的代码
(亲测有效)

#include <pcl/search/impl/search.hpp>
#ifndef PCL_NO_PRECOMPILE
#include <pcl/impl/instantiate.hpp>
#include <pcl/point_types.h>
PCL_INSTANTIATE(Search, PCL_POINT_TYPES)
#endif // PCL_NO_PRECOMPILE

转载链接:
[1] PCL之使用过程中遇到的坑 https://blog.csdn.net/hehehetanchaow/article/details/82745262?depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromBaidu-3&utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromBaidu-3

2.运行报错:[pcl::SHOTEstimation::computeFeature] The local reference frame is not valid! Aborting description of point with index 3115

在这里插入图片描述这个错误是因为正常半径较小的事实,一些法线是NaN(在设置半径的球体内它们的邻域中没有点)。这曾经导致计算SHOT描述子出现问题,

解决方法

只需要改大代码中的参数 descr_rad_ (搜索半径)就可以

float descr_rad_ (2.0f);//原来是0.02f时运行会报错

另外,可能还需要设置线程数descr_est.setNumberOfThreads(4);,否则可能报错
在这里插入图片描述
参考链接:
[1] 【毕业课题学习】PCL-基于对应分组的三维物体识别 https://blog.csdn.net/weixin_41835977/article/details/87626852

3.编译报错 error: ‘const class pcl::PointCloud<pcl::PointXYZ>’ has no member named ‘__getMD5Sum’

/opt/ros/kinetic/include/ros/message_traits.h:126:14: error: ‘const class pcl::PointCloud<pcl::PointXYZ>’ has no member named ‘__getMD5Sum’
     return m.__getMD5Sum().c_str();

/opt/ros/kinetic/include/ros/message_traits.h:143:14: error: ‘const class pcl::PointCloud<pcl::PointXYZ>’ has no member named ‘__getDataType’
     return m.__getDataType().c_str();
     
/opt/ros/kinetic/include/ros/message_traits.h:143:14: error: ‘const class pcl::PointCloud<pcl::PointXYZ>’ has no member named ‘__getDataType’
     return m.__getDataType().c_str();
     /opt/ros/kinetic/include/ros/serialization.h:144:14: error: ‘const class pcl::PointCloud<pcl::PointXYZ>’ has no member named ‘serializationLength’
     return t.serializationLength();
     
/opt/ros/kinetic/include/ros/serialization.h:127:7: error: ‘const class pcl::PointCloud<pcl::PointXYZ>’ has no member named ‘serialize’; did you mean ‘isOrganized’?
     t.serialize(stream.getData(), 0);

解决方法

需要添加对应的头文件,就可以编译通过了。

#include  <pcl_ros/point_cloud.h>

自己遇到的情况所对应的解决方法:
自己是在使用 pcl 数据类型 pcl::PointCloudpcl::PointXYZ::Ptr 与 ros中数据类型 sensor_msgs::PointCloud2 之间的转换问题,

#include  <pcl_ros/point_cloud.h>

ros::Publisher localSubmapPub = nh.advertise<sensor_msgs::PointCloud2>("localmap", 5, true);

pcl::PointCloud<pcl::PointXYZ>::Ptr localSubmap;
localSubmapPub.publish(localSubmap);//localSubmap 在程序其他的地方会被赋值

这里需要注意的点就是 localSubmapPub.publish() 函数理论上传入的参数应该是 sensor_msgs::PointCloud2 类型,但是这里传入的是 pcl::PointCloud<pcl::PointXYZ>::Ptr 类型。(因为之前看到别人有这样写过,所以自己也准备这样写)。

因为想到这涉及到他们之间的关系,所以我这里添加对应的头文件,结果就可以编译通过了!!!

#include  <pcl_ros/point_cloud.h>

4.编译报错 undefined reference to pcl::search::KdTree<pcl::PointXYZ>::KdTree(bool)

最近编译ROS功能包,
编译时候遇到如下报错:

CMakeFiles/SnapMapICP.dir/src/SnapMapICP.cpp.o: In function `pcl::Registration<pcl::PointXYZ, pcl::PointXYZ, float>::Registration()':
SnapMapICP.cpp:(.text._ZN3pcl12RegistrationINS_8PointXYZES1_fEC2Ev[_ZN3pcl12RegistrationINS_8PointXYZES1_fEC5Ev]+0x4d): undefined reference to `pcl::search::KdTree<pcl::PointXYZ>::KdTree(bool)'
SnapMapICP.cpp:(.text._ZN3pcl12RegistrationINS_8PointXYZES1_fEC2Ev[_ZN3pcl12RegistrationINS_8PointXYZES1_fEC5Ev]+0x7a): undefined reference to `pcl::search::KdTree<pcl::PointXYZ>::KdTree(bool)'
CMakeFiles/SnapMapICP.dir/src/SnapMapICP.cpp.o: In function `pcl::Registration<pcl::PointXYZ, pcl::PointXYZ, float>::align(pcl::PointCloud<pcl::PointXYZ>&, Eigen::Matrix<float, 4, 4, 0, 4, 4> const&)':
SnapMapICP.cpp:(.text._ZN3pcl12RegistrationINS_8PointXYZES1_fE5alignERNS_10PointCloudIS1_EERKN5Eigen6MatrixIfLi4ELi4ELi0ELi4ELi4EEE[_ZN3pcl12RegistrationINS_8PointXYZES1_fE5alignERNS_10PointCloudIS1_EERKN5Eigen6MatrixIfLi4ELi4ELi0ELi4ELi4EEE]+0x275): undefined reference to `pcl::search::KdTree<pcl::PointXYZ>::setPointRepresentation(boost::shared_ptr<pcl::PointRepresentation<pcl::PointXYZ> const> const&)'
CMakeFiles/SnapMapICP.dir/src/SnapMapICP.cpp.o: In function `pcl::registration::CorrespondenceEstimationBase<pcl::PointXYZ, pcl::PointXYZ, float>::CorrespondenceEstimationBase()':
SnapMapICP.cpp:(.text._ZN3pcl12registration28CorrespondenceEstimationBaseINS_8PointXYZES2_fEC2Ev[_ZN3pcl12registration28CorrespondenceEstimationBaseINS_8PointXYZES2_fEC5Ev]+0x71): undefined reference to `pcl::search::KdTree<pcl::PointXYZ>::KdTree(bool)'
SnapMapICP.cpp:(.text._ZN3pcl12registration28CorrespondenceEstimationBaseINS_8PointXYZES2_fEC2Ev[_ZN3pcl12registration28CorrespondenceEstimationBaseINS_8PointXYZES2_fEC5Ev]+0x9e): undefined reference to `pcl::search::KdTree<pcl::PointXYZ>::KdTree(bool)'
CMakeFiles/SnapMapICP.dir/src/SnapMapICP.cpp.o: In function `pcl::registration::CorrespondenceEstimationBase<pcl::PointXYZ, pcl::PointXYZ, float>::initComputeReciprocal()':
SnapMapICP.cpp:(.text._ZN3pcl12registration28CorrespondenceEstimationBaseINS_8PointXYZES2_fE21initComputeReciprocalEv[_ZN3pcl12registration28CorrespondenceEstimationBaseINS_8PointXYZES2_fE21initComputeReciprocalEv]+0x74): undefined reference to `pcl::search::KdTree<pcl::PointXYZ>::setPointRepresentation(boost::shared_ptr<pcl::PointRepresentation<pcl::PointXYZ> const> const&)'
CMakeFiles/SnapMapICP.dir/src/SnapMapICP.cpp.o: In function `pcl::registration::CorrespondenceEstimationBase<pcl::PointXYZ, pcl::PointXYZ, float>::setInputTarget(boost::shared_ptr<pcl::PointCloud<pcl::PointXYZ> const> const&)':
SnapMapICP.cpp:(.text._ZN3pcl12registration28CorrespondenceEstimationBaseINS_8PointXYZES2_fE14setInputTargetERKN5boost10shared_ptrIKNS_10PointCloudIS2_EEEE[_ZN3pcl12registration28CorrespondenceEstimationBaseINS_8PointXYZES2_fE14setInputTargetERKN5boost10shared_ptrIKNS_10PointCloudIS2_EEEE]+0xab): undefined reference to `pcl::search::KdTree<pcl::PointXYZ>::setPointRepresentation(boost::shared_ptr<pcl::PointRepresentation<pcl::PointXYZ> const> const&)'
collect2: error: ld returned 1 exit status
make[2]: *** [/home/shansu/reflector_ws/devel/lib/snap_map_icp/SnapMapICP] Error 1
make[1]: *** [snap_map_icp/CMakeFiles/SnapMapICP.dir/all] Error 2
make: *** [all] Error 2
Invoking "make -j4 -l4" failed

解决方法

发现报错提示的是 关于 pcl::search::KdTree 的,所以考虑到是否包含了对应的头文件,然后在对应的 报错cpp
中添加如下头文件,就可以编译通过啦~~~~~

#include <pcl/search/impl/kdtree.hpp>

(这个问题自己搞了一天,自己这个包已经在其他电脑上测试通过了,但是就就是在目标电脑上编译报错,所以刚开始一直以为是 pcl 版本的问题,修改了CMakeLists.txt 依旧报这个错误,搞得自己很迷,最终竟让是缺少头文件导致的…
不过还好,解决了这个问题。)

以后遇到这种 undefined reference to **** 报错,先考虑是否包含了头文件!!!

参考链接:
[1] Linker errors with PCL 1.8.0 project – https://stackoverflow.com/questions/44253353/linker-errors-with-pcl-1-8-0-project
[2] undefined reference to ‘pcl::KdTreeFLANN PointInT,flann:: L2_Simple float ::setSortedResults(bool)’ – https://blog.csdn.net/weixin_42718092/article/details/94874997

5.运行报错 typename boost::detail::sp_member_access<T>::type = pcl::KdTree<pcl::PointXYZ>*]: Assertion px != 0 failed.

运行关于PCL的c++程序的时候,遇到如下问题:

/usr/include/boost/smart_ptr/shared_ptr.hpp:648: typename boost::detail::sp_member_access<T>::type boost::shared_ptr<T>::operator->() const [with T = pcl::KdTree<pcl::PointXYZ>; typename boost::detail::sp_member_access<T>::type = pcl::KdTree<pcl::PointXYZ>*]: Assertion `px != 0' failed.
Aborted

原因就是:智能指针未初始化。在PCL中一定要初始化!初始化!初始化!初始化!

解决方法

在使用PCL指针的时候,记得初始化!

pcl::KdTreeFLANN<pcl::PointXYZ>::Ptr tree;
tree.reset (new pcl::KdTreeFLANN<pcl::PointXYZ>); 

或者直接改为

pcl::KdTreeFLANN<pcl::PointXYZ>::Ptr tree (new pcl::KdTreeFLANN<pcl::PointXYZ>);

参考链接:
[1] PCL:遇到的一些问题及解决方案 https://blog.csdn.net/felaim/article/details/77504763

6.编译报错 undefined reference to pcl::KdTreeFLANN< pcl::PointXYZ, flann::L2_Simple<float>> ::KdTreeFLANN(bool)

最近测试编译kd tree 的时候遇到如下的诡异报错,在程序中,做了如下操作:

pcl::KdTree<pcl::PointXYZ>::Ptr tree;
tree.reset (new pcl::KdTreeFLANN<pcl::PointXYZ>);    //加上这句就报错??? 报错:undefined reference to pcl::KdTreeFLANN<pcl::PointXYZ, flann::L2_Simple<float> >::KdTreeFLANN(bool)
tree->setInputCloud (cloudb);

报错信息:

CMakeFiles/kdtree_search.dir/src/kdtree_search.cpp.o: In function `getTree(boost::shared_ptr<pcl::PointCloud<pcl::PointXYZ> >)':
kdtree_search.cpp:(.text+0x46): undefined reference to `pcl::KdTreeFLANN<pcl::PointXYZ, flann::L2_Simple<float> >::KdTreeFLANN(bool)'
collect2: error: ld returned 1 exit status
CMakeFiles/kdtree_search.dir/build.make:94: recipe for target 'kdtree_search' failed
make[2]: *** [kdtree_search] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/kdtree_search.dir/all' failed
make[1]: *** [CMakeFiles/kdtree_search.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

解决方法

自己对比了各种头文件,发现头文件都已经正常包含,最后发现是 CMakeLists.txt 写的有问题…
自己的 CMakeLists.txt 是这样写的:

cmake_minimum_required(VERSION 2.8)
project(kd_tree)
find_package(PCL 1.7 REQUIRED)

include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})

add_executable(kdtree_search src/kdtree_search.cpp)
target_link_libraries(kdtree_search ${PCL_LIBRARY_DIRS})

这里把 最后一句

target_link_libraries(kdtree_search ${PCL_LIBRARY_DIRS})

改为

target_link_libraries(kdtree_search ${PCL_LIBRARIES})

就可以编译成功啦~~~

7.编译报错 /usr/include/pcl-1.7/pcl/octree/octree_pointcloud_changedetector.h:64:43: error: ‘Octree2BufBase’ was not declared in this scop

自己的测试环境:Ubuntu 16.04 、PCL-1.7

最近在学习使用 Octree,在编译例程的时候遇到如下问题

/usr/include/pcl-1.7/pcl/octree/octree_pointcloud_changedetector.h:64:43: error: ‘Octree2BufBase’ was not declared in this scope
         LeafContainerT, BranchContainerT, Octree2BufBase<LeafContainerT, BranchContainerT> >

解决方法

出现这个问题的主要原因是 程序中包含了 头文件 #include <pcl/octree/octree_pointcloud_changedetector.h> ,但是 文件 pcl/octree/octree_pointcloud_changedetector.h 中缺少一个头文件 #include "octree2buf_base.h",所以需要在 octree_pointcloud_changedetector.h 中添加这个头文件。

执行命令打开文件:

sudo gedit /usr/include/pcl-1.7/pcl/octree/octree_pointcloud_changedetector.h

然后添加如下头文件:

#include "octree2buf_base.h"

在这里插入图片描述

然后重新编译就可以编译通过啦~~··

参考链接

[1] RogerAylagas. error: ‘Octree2BufBase’ was not declared in this scope #2564 [EB/OL]. https://github.com/PointCloudLibrary/pcl/issues/2564, 2018-10-17/2021-06-09

8.编译报错:error: ‘transformPointCloud’ is not a member of ‘pcl’

error: ‘transformPointCloud’ is not a member of ‘pcl’
     pcl::transformPointCloud(*globalmap, *transformed_z, transformation_z)

解决方法

出现这个错误的原因就是没有添加头文件, 在相应位置添加头文件就可以.

#include <pcl/common/transforms.h>

9.编译报错:undefined reference to `ros::init

globalmap_server.cpp:(.text+0x70): undefined reference to `ros::init(int&, char**, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned int)'
globalmap_server.cpp:(.text+0xa2): undefined reference to `ros::spin()'

解决方法

主要在 CMakeLists.txt 文件中的配置不太对, target_link_libraries 后面需要链接到对应的库 ${catkin_LIBRARIES} .

原本是

target_link_libraries(main_node )

需要改为

target_link_libraries(main_node  ${catkin_LIBRARIES} )
评论 16
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值