Environment:
Ubuntu 20.04, PCL 1.11.0
when compiling PCL with cmake, an error is reported:
/usr/bin/ld: CMakeFiles/MYSLAM.dir/src/voslam.cpp.o:(.data.rel.ro._ZTVN3pcl7PCLBaseINS_12PointXYZRGBAEEE[_ZTVN3pcl7PCLBaseINS_12PointXYZRGBAEEE]+0x20): undefined reference to `pcl::PCLBase<pcl::PointXYZRGBA>::setInputCloud(std::shared_ptr<pcl::PointCloud<pcl::PointXYZRGBA> const> const&)'
/usr/bin/ld: CMakeFiles/MYSLAM.dir/src/voslam.cpp.o:(.data.rel.ro._ZTVN3pcl7PCLBaseINS_12PointXYZRGBAEEE[_ZTVN3pcl7PCLBaseINS_12PointXYZRGBAEEE]+0x28): undefined reference to `pcl::PCLBase<pcl::PointXYZRGBA>::setIndices(std::shared_ptr<std::vector<int, std::allocator<int> > > const&)'
/usr/bin/ld: CMakeFiles/MYSLAM.dir/src/voslam.cpp.o:(.data.rel.ro._ZTVN3pcl7PCLBaseINS_12PointXYZRGBAEEE[_ZTVN3pcl7PCLBaseINS_12PointXYZRGBAEEE]+0x30): undefined reference to `pcl::PCLBase<pcl::PointXYZRGBA>::setIndices(std::shared_ptr<std::vector<int, std::allocator<int> > const> const&)'
/usr/bin/ld: CMakeFiles/MYSLAM.dir/src/voslam.cpp.o:(.data.rel.ro._ZTVN3pcl7PCLBaseINS_12PointXYZRGBAEEE[_ZTVN3pcl7PCLBaseINS_12PointXYZRGBAEEE]+0x38): undefined reference to `pcl::PCLBase<pcl::PointXYZRGBA>::setIndices(std::shared_ptr<pcl::PointIndices const> const&)'
/usr/bin/ld: CMakeFiles/MYSLAM.dir/src/voslam.cpp.o:(.data.rel.ro._ZTVN3pcl7PCLBaseINS_12PointXYZRGBAEEE[_ZTVN3pcl7PCLBaseINS_12PointXYZRGBAEEE]+0x40): undefined reference to `pcl::PCLBase<pcl::PointXYZRGBA>::setIndices(unsigned long, unsigned long, unsigned long, unsigned long)'
/usr/bin/ld: CMakeFiles/MYSLAM.dir/src/voslam.cpp.o:(.data.rel.ro._ZTVN3pcl6FilterINS_12PointXYZRGBAEEE[_ZTVN3pcl6FilterINS_12PointXYZRGBAEEE]+0x20): undefined reference to `pcl::PCLBase<pcl::PointXYZRGBA>::setInputCloud(std::shared_ptr<pcl::PointCloud<pcl::PointXYZRGBA> const> const&)'
/usr/bin/ld: CMakeFiles/MYSLAM.dir/src/voslam.cpp.o:(.data.rel.ro._ZTVN3pcl6FilterINS_12PointXYZRGBAEEE[_ZTVN3pcl6FilterINS_12PointXYZRGBAEEE]+0x28): undefined reference to `pcl::PCLBase<pcl::PointXYZRGBA>::setIndices(std::shared_ptr<std::vector<int, std::allocator<int> > > const&)'
/usr/bin/ld: CMakeFiles/MYSLAM.dir/src/voslam.cpp.o:(.data.rel.ro._ZTVN3pcl6FilterINS_12PointXYZRGBAEEE[_ZTVN3pcl6FilterINS_12PointXYZRGBAEEE]+0x30): undefined reference to `pcl::PCLBase<pcl::PointXYZRGBA>::setIndices(std::shared_ptr<std::vector<int, std::allocator<int> > const> const&)'
/usr/bin/ld: CMakeFiles/MYSLAM.dir/src/voslam.cpp.o:(.data.rel.ro._ZTVN3pcl6FilterINS_12PointXYZRGBAEEE[_ZTVN3pcl6FilterINS_12PointXYZRGBAEEE]+0x38): undefined reference to `pcl::PCLBase<pcl::PointXYZRGBA>::setIndices(std::shared_ptr<pcl::PointIndices const> const&)'
/usr/bin/ld: CMakeFiles/MYSLAM.dir/src/voslam.cpp.o:(.data.rel.ro._ZTVN3pcl6FilterINS_12PointXYZRGBAEEE[_ZTVN3pcl6FilterINS_12PointXYZRGBAEEE]+0x40): undefined reference to `pcl::PCLBase<pcl::PointXYZRGBA>::setIndices(unsigned long, unsigned long, unsigned long, unsigned long)'
/usr/bin/ld: CMakeFiles/MYSLAM.dir/src/voslam.cpp.o:(.data.rel.ro._ZTVN3pcl9VoxelGridINS_12PointXYZRGBAEEE[_ZTVN3pcl9VoxelGridINS_12PointXYZRGBAEEE]+0x20): undefined reference to `pcl::PCLBase<pcl::PointXYZRGBA>::setInputCloud(std::shared_ptr<pcl::PointCloud<pcl::PointXYZRGBA> const> const&)'
/usr/bin/ld: CMakeFiles/MYSLAM.dir/src/voslam.cpp.o:(.data.rel.ro._ZTVN3pcl9VoxelGridINS_12PointXYZRGBAEEE[_ZTVN3pcl9VoxelGridINS_12PointXYZRGBAEEE]+0x28): undefined reference to `pcl::PCLBase<pcl::PointXYZRGBA>::setIndices(std::shared_ptr<std::vector<int, std::allocator<int> > > const&)'
/usr/bin/ld: CMakeFiles/MYSLAM.dir/src/voslam.cpp.o:(.data.rel.ro._ZTVN3pcl9VoxelGridINS_12PointXYZRGBAEEE[_ZTVN3pcl9VoxelGridINS_12PointXYZRGBAEEE]+0x30): undefined reference to `pcl::PCLBase<pcl::PointXYZRGBA>::setIndices(std::shared_ptr<std::vector<int, std::allocator<int> > const> const&)'
/usr/bin/ld: CMakeFiles/MYSLAM.dir/src/voslam.cpp.o:(.data.rel.ro._ZTVN3pcl9VoxelGridINS_12PointXYZRGBAEEE[_ZTVN3pcl9VoxelGridINS_12PointXYZRGBAEEE]+0x38): undefined reference to `pcl::PCLBase<pcl::PointXYZRGBA>::setIndices(std::shared_ptr<pcl::PointIndices const> const&)'
/usr/bin/ld: CMakeFiles/MYSLAM.dir/src/voslam.cpp.o:(.data.rel.ro._ZTVN3pcl9VoxelGridINS_12PointXYZRGBAEEE[_ZTVN3pcl9VoxelGridINS_12PointXYZRGBAEEE]+0x40): undefined reference to `pcl::PCLBase<pcl::PointXYZRGBA>::setIndices(unsigned long, unsigned long, unsigned long, unsigned long)'
/usr/bin/ld: CMakeFiles/MYSLAM.dir/src/voslam.cpp.o:(.data.rel.ro._ZTVN3pcl9VoxelGridINS_12PointXYZRGBAEEE[_ZTVN3pcl9VoxelGridINS_12PointXYZRGBAEEE]+0x48): undefined reference to `pcl::VoxelGrid<pcl::PointXYZRGBA>::applyFilter(pcl::PointCloud<pcl::PointXYZRGBA>&)'
/usr/bin/ld: CMakeFiles/MYSLAM.dir/src/pointcloudmapping.cpp.o: in function `PointCloudMapping::PointCloudMapping(double)':
pointcloudmapping.cpp:(.text+0x1ac): undefined reference to `pcl::PCLBase<pcl::PointXYZRGBA>::PCLBase()'
/usr/bin/ld: CMakeFiles/MYSLAM.dir/src/pointcloudmapping.cpp.o: in function `PointCloudMapping::viewer()':
pointcloudmapping.cpp:(.text+0x1626): undefined reference to `pcl::visualization::CloudViewer::CloudViewer(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/usr/bin/ld: pointcloudmapping.cpp:(.text+0x1d39): undefined reference to `pcl::PCLBase<pcl::PointXYZRGBA>::setInputCloud(std::shared_ptr<pcl::PointCloud<pcl::PointXYZRGBA> const> const&)'
/usr/bin/ld: pointcloudmapping.cpp:(.text+0x1d66): undefined reference to `pcl::PCLBase<pcl::PointXYZRGBA>::initCompute()'
/usr/bin/ld: pointcloudmapping.cpp:(.text+0x1db5): undefined reference to `pcl::VoxelGrid<pcl::PointXYZRGBA>::applyFilter(pcl::PointCloud<pcl::PointXYZRGBA>&)'
/usr/bin/ld: pointcloudmapping.cpp:(.text+0x1dbd): undefined reference to `pcl::PCLBase<pcl::PointXYZRGBA>::deinitCompute()'
/usr/bin/ld: pointcloudmapping.cpp:(.text+0x1ff7): undefined reference to `pcl::visualization::CloudViewer::showCloud(std::shared_ptr<pcl::PointCloud<pcl::PointXYZRGBA> const> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/usr/bin/ld: pointcloudmapping.cpp:(.text+0x24dd): undefined reference to `pcl::VoxelGrid<pcl::PointXYZRGBA>::applyFilter(pcl::PointCloud<pcl::PointXYZRGBA>&)'
/usr/bin/ld: pointcloudmapping.cpp:(.text+0x263d): undefined reference to `pcl::visualization::CloudViewer::~CloudViewer()'
/usr/bin/ld: pointcloudmapping.cpp:(.text+0x2798): undefined reference to `pcl::visualization::CloudViewer::~CloudViewer()'
collect2: error: ld returned 1 exit status
Solution:
manually specify the header file and link library of PCL:
# find_package(PCL 1.11.0 EXACT REQUIRED)
# add_definitions( ${PCL_DEFINITIONS} )
-------Modify---:
file(GLOB PCL_LIBRARIES /usr/local/lib/libpcl_*)
set(PCL_INCLUDE_DIRS /usr/local/include/pcl-1.11)
INCLUDE_DIRECTORIES(${PROJECT_NAME} ${PCL_INCLUDE_DIRS})
TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${PCL_LIBRARIES})