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})
Read More:
- Solve error LNK2001 about pcl::io::vtkPolyDataToPointCloud
- PCL 1.8.1 VTK 9.0 QT 5.14.9 [How to Solve]
- Windows: How to Solve PCL C2065 Error
- [Solved] PCL Install error: ‘shared_ptr’ does not name a type
- error C4996: ‘pcl::SAC_SAMPLE_SIZE‘ [How to Solve]
- [Solved] Compile Error: undefined reference to `google::FlagRegisterer::FlagRegisterer
- error: #error PCL requires C++14 or above [Solved]
- Error: # error PCL requires C++ 14 or above
- [Solved] C++ error: undefined reference to `xxx‘
- [Solved] Compile the program error: undefined reference to `cv::dnn::dnn4_v20210301::Net::~Net()‘
- Clion new method shows undefined reference to solution
- error: undefined reference to `calculate()` [How to Solve]
- [Solved] Qt Error: undefined reference to xxxxx
- [Solved] cortex_M3 freeRTOS Error: undefined reference to `_sbrk‘
- GCC Error:(.text+0x24): undefined reference to `main‘collect2: error: ld returned 1 exit status [Solved]
- [Solved] QT error: error: undefined reference to ` VTable`
- C++Qt development – Qtsocket programming error: undefined reference to `_imp__WSAStartup
- [Solved] latex Compile llncs2e reference error locally
- [Solved] VScode Error: undefined reference to ‘WinMain’ collect2.exe: error: ld returned 1 exit status
- [Solved] QT Error: error: undefined reference to `GameModel::~GameModel()’