这篇博客准备记录PCL使用过程中遇到坑
undefined reference to pcl::search::Search::getName[ abi:cxx11]() const
undefined reference to `pcl::search::Search<pcl::PointXYZRGBA>::getName[abi:cxx11]() const'
这类问题是由于pcl的版本导致,解决方案:安装更新的pcl;
或者添加下面的代码
(亲测有效)
#include
#ifndef PCL_NO_PRECOMPILE
#include
#include
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
[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
error: ‘const class pcl::PointCloud’ 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 数据类型 pcl::PointCloudpcl::PointXYZ::Ptr 与 ros中数据类型 sensor_msgs::PointCloud2 之间的转换问题,
#include
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
类型。(因为之前看到别人有这样写过,所以自己也准备这样写)。
因为想到这涉及到他们之间的关系,所以我这里添加对应的头文件,结果就可以编译通过了!!!
#include
undefined reference to pcl::search::KdTree::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::align(pcl::PointCloud&, Eigen::Matrix 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::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::setPointRepresentation(boost::shared_ptr 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 版本的问题,修改了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
typename boost::detail::sp_member_access::type = pcl::KdTree*]: 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
undefined reference to pcl::KdTreeFLANN< pcl::PointXYZ, flann::L2_Simple> ::KdTreeFLANN(bool)
最近测试编译kd tree 的时候遇到如下的诡异报错,在程序中,做了如下操作:
pcl::KdTree<pcl::PointXYZ>::Ptr tree;
tree.reset (new pcl::KdTreeFLANN<pcl::PointXYZ>); //加上这句就报错??? 报错:undefined reference to pcl::KdTreeFLANN >::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})
就可以编译成功啦~~~
自己的测试环境: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
中缺少一个头文件 #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
error: ‘transformPointCloud’ is not a member of ‘pcl’
pcl::transformPointCloud(*globalmap, *transformed_z, transformation_z)
出现这个错误的原因就是没有添加头文件, 在相应位置添加头文件就可以.
#include
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} )