PCL 和 CMake 的问题:链接时未定义统计异常值删除

Issue with PCL and CMake : StatisticalOutlierRemoval undefined while linking

本文关键字:统计 未定义 异常 删除 链接 CMake 问题 PCL      更新时间:2023-10-16

我目前正在尝试使用 PCL 过滤 pointCloud,这要归功于 StatisticalOutlierRemoval 而不使用 ROS,仅使用 PCL 我通过官方 github 存储库安装。我在代码中使用它,链接时出现以下错误:

CMakeFiles/tests/11_pcl/removeOutliers.dir/removeOutliers.cpp.o: In function `pcl::StatisticalOutlierRemoval<pcl::PointXYZRGB>::applyFilter(std::vector<int, std::allocator<int> >&)':
removeOutliers.cpp:(.text._ZN3pcl25StatisticalOutlierRemovalINS_11PointXYZRGBEE11applyFilterERSt6vectorIiSaIiEE[_ZN3pcl25StatisticalOutlierRemovalINS_11PointXYZRGBEE11applyFilterERSt6vectorIiSaIiEE]+0x1): undefined reference to `pcl::StatisticalOutlierRemoval<pcl::PointXYZRGB>::applyFilterIndices(std::vector<int, std::allocator<int> >&)'
CMakeFiles/tests/11_pcl/removeOutliers.dir/removeOutliers.cpp.o:(.rodata._ZTVN3pcl25StatisticalOutlierRemovalINS_11PointXYZRGBEEE[_ZTVN3pcl25StatisticalOutlierRemovalINS_11PointXYZRGBEEE]+0x48): undefined reference to `pcl::StatisticalOutlierRemoval<pcl::PointXYZRGB>::applyFilter(pcl::PointCloud<pcl::PointXYZRGB>&)'

在我的CMakeList中,我有以下几行:

find_package(PCL 1.3 REQUIRED COMPONENTS common io visualization)
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})

和:

add_executable(tests/11_pcl/removeOutliers removeOutliers.cpp)
target_link_libraries(tests/11_pcl/removeOutliers ${PCL_LIBRARIES} ${OpenCV_LIBS})    

在我的 cpp 文件中,我只尝试使用 :

pcl::StatisticalOutlierRemoval<pcl::PointXYZRGB> sor;

我有以下标题:

#include <pcl/common/common_headers.h>
#include <pcl/features/normal_3d.h>
#include <pcl/io/pcd_io.h>
#include <pcl/visualization/pcl_visualizer.h>
#include <pcl/console/parse.h>
//Filters
#include <pcl/point_types.h>
#include <pcl/filters/statistical_outlier_removal.h>

我想我可能在 PCL 中缺少一个组件......知道吗?

好的,我已经找到了解决方案。我实际上缺少PCL(过滤器(中的组件。

find_package(PCL 1.3 REQUIRED COMPONENTS common io visualization filters)

现在一切正常。