本文主要是介绍ros的pcl库中对于自己定义的消息,调用pcl库时总是报错 c++,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
首先定义自己的消息类型
struct CustomPoint { // 定义点类型结构PCL_ADD_POINT4D; // 该点类型有4个元素float intensity = 0.0;uint32_t zone;uint32_t ring;uint32_t sector;EIGEN_MAKE_ALIGNED_OPERATOR_NEW // 确保new操作符对齐操作
} EIGEN_ALIGN16; // 强制SSE对齐POINT_CLOUD_REGISTER_POINT_STRUCT( // 注册点类型宏CustomPoint,(float, x, x)(float, y, y)(float, z, z)(float, intensity, intensity)(uint32_t, zone, zone)(uint32_t, ring, ring)(uint32_t, sector, sector)
)// typedef pcl::PointXYZI VPoint;
typedef CustomPoint VPoint;
typedef pcl::PointCloud<VPoint> VPointType;
在定义完自己的消息类型之后,调用pcl::removeNaNFromPointCloud等自带的函数时会报错:
(.text+0x14631): undefined reference to `pcl::PCLBase<CustomPoint>::PCLBase(
cl::removeNaNFromPointCloud<CustomPoint>(pcl::PointCloud<CustomPoint> const&, pcl::PointCloud<CustomPoint>&, std::vector<int, std::allocator<int> >&)'
collect2: error: ld returned 1 exit status
代码如下:
void PatchWorkpp::pointcloud_callback(const sensor_msgs::PointCloud2::ConstPtr &input){VPointType::Ptr cloud_in = boost::make_shared<VPointType>();VPointType::Ptr src_cloud(new VPointType);pcl::fromROSMsg(*input, *cloud_in);std::vector<int> mapping;pcl::removeNaNFromPointCloud(*cloud_in, *cloud_in, mapping); // 必须要移除NAN点}
此时需要添加头文件如下:
#include <pcl/impl/pcl_base.hpp>
#include <pcl/filters/impl/crop_box.hpp>
#include <pcl/filters/impl/filter.hpp>
#include <pcl/kdtree/impl/kdtree_flann.hpp>
#include <pcl/search/impl/organized.hpp>
#include <pcl/surface/impl/convex_hull.hpp>
参考文章:
https://blog.csdn.net/qq_43427457/article/details/125052803
这篇关于ros的pcl库中对于自己定义的消息,调用pcl库时总是报错 c++的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!