《PCL点云库学习&VS2010(X64)》Part 44 EuclideanClusterExtraction函数相关库链接错误
在使用欧式聚类时,发现debug版本可以编译通过并正常运行,而在release版本中,直接编译不通过,开始以为是库编译出了问题,后来在maillist中发现有人遇到同样的问题。
具体错误:
error LINK2019:无法解析的外部符号“public: void __cdecl pcl::EuclideanClusterExtraction<struct pcl::PointNormal> ::extract(class std::vector<pcl::PointIndices,class std::allocator<struct pcl::PointIndices>>&)”......
解决方法:
除了正常的加入的头文件:
#include <pcl::segmentation/extract_clusters.h>
还需加入一下hpp文件才能编译通过:
#include <pcl/segmentation/impl/extract_clusters.hpp>
上面的这个应该就能编译通过了,如果不行,继续加入下面头文件:
#include <pcl/search/impl/search.hpp>
编译通过,问题解决。
///////////////////////////////////////////////////////////////////////////
以上问题在QT中使用时没有任何问题,在MFC中使用时需要注意,可能由于编译器的原因,对于std::numeric_limits::max()函数会报错,使用欧式聚类:
pcl::search::KdTree<PointNormal>::Ptr segtree (new pcl::search::KdTree<PointNormal>);
segtree->setInputCloud (doncloud);
std::vector<pcl::PointIndices> cluster_indices;
pcl::EuclideanClusterExtraction<PointNormal> ec;
ec.setClusterTolerance (segradius);
ec.setMinClusterSize (50);
ec.setMaxClusterSize (100000);
ec.setSearchMethod (segtree);
ec.setInputCloud (doncloud);
ec.extract (cluster_indices);
pcl::EuclideanClusterExtraction ec;此句会报错,由于代码阅读差错时的大意,多次定位到该处但没有解决掉,很莫名其妙的错误。
解决方法:
1、定位到欧式聚类对应的extract_cluster.h头文件中,发现该构造函数的最大聚类参数:max_pts_per_cluster_(std::numeric_limits::max())
2、将上句改为: max_pts_per_cluster_(std::numeric_limits::max()),重新编译,通过。