无法链接PCL库undefined reference to `pcl::****

无法链接PCL库undefined reference to `pcl:😗***

../lib/libORB_SLAM2.so: undefined reference to `pcl::PCLBase<pcl::PointXYZRGBA>::setIndices(boost::shared_ptr<std::vector<int, std::allocator<int> > const> const&)'
../lib/libORB_SLAM2.so: undefined reference to `pcl::PCLBase<pcl::PointXYZRGBA>::PCLBase()'
../lib/libORB_SLAM2.so: undefined reference to `pcl::PCLBase<pcl::PointXYZRGBA>::deinitCompute()'
../lib/libORB_SLAM2.so: undefined reference to `pcl::visualization::CloudViewer::showCloud(boost::shared_ptr<pcl::PointCloud<pcl::PointXYZRGBA> const> const&, std::string const&)'
../lib/libORB_SLAM2.so: undefined reference to `pcl::visualization::CloudViewer::~CloudViewer()'
../lib/libORB_SLAM2.so: undefined reference to `pcl::PCLBase<pcl::PointXYZRGBA>::setIndices(unsigned long, unsigned long, unsigned long, unsigned long)'
../lib/libORB_SLAM2.so: undefined reference to `pcl::visualization::CloudViewer::CloudViewer(std::string const&)'
../lib/libORB_SLAM2.so: undefined reference to `pcl::PCLBase<pcl::PointXYZRGBA>::setIndices(boost::shared_ptr<std::vector<int, std::allocator<int> > > const&)'
../lib/libORB_SLAM2.so: undefined reference to `pcl::VoxelGrid<pcl::PointXYZRGBA>::applyFilter(pcl::PointCloud<pcl::PointXYZRGBA>&)'
../lib/libORB_SLAM2.so: undefined reference to `pcl::PCLBase<pcl::PointXYZRGBA>::initCompute()'
../lib/libORB_SLAM2.so: undefined reference to `pcl::PCLBase<pcl::PointXYZRGBA>::setInputCloud(boost::shared_ptr<pcl::PointCloud<pcl::PointXYZRGBA> const> const&)'
../lib/libORB_SLAM2.so: undefined reference to `pcl::PCLBase<pcl::PointXYZRGBA>::setIndices(boost::shared_ptr<pcl::PointIndices const> const&)'
collect2: error: ld returned 1 exit status
make[2]: *** [../Examples/Stereo/stereo_kitti] Error 1
make[1]: *** [CMakeFiles/stereo_kitti.dir/all] Error 2
[100%] Linking CXX executable ../Examples/Stereo/stereo_euroc
../lib/libORB_SLAM2.so: undefined reference to `pcl::PCLBase<pcl::PointXYZRGBA>::setIndices(boost::shared_ptr<std::vector<int, std::allocator<int> > const> const&)'
../lib/libORB_SLAM2.so: undefined reference to `pcl::PCLBase<pcl::PointXYZRGBA>::PCLBase()'
../lib/libORB_SLAM2.so: undefined reference to `pcl::PCLBase<pcl::PointXYZRGBA>::deinitCompute()'
../lib/libORB_SLAM2.so: undefined reference to `pcl::visualization::CloudViewer::showCloud(boost::shared_ptr<pcl::PointCloud<pcl::PointXYZRGBA> const> const&, std::string const&)'
../lib/libORB_SLAM2.so: undefined reference to `pcl::visualization::CloudViewer::~CloudViewer()'
../lib/libORB_SLAM2.so: undefined reference to `pcl::PCLBase<pcl::PointXYZRGBA>::setIndices(unsigned long, unsigned long, unsigned long, unsigned long)'
../lib/libORB_SLAM2.so: undefined reference to `pcl::visualization::CloudViewer::CloudViewer(std::string const&)'
../lib/libORB_SLAM2.so: undefined reference to `pcl::PCLBase<pcl::PointXYZRGBA>::setIndices(boost::shared_ptr<std::vector<int, std::allocator<int> > > const&)'
../lib/libORB_SLAM2.so: undefined reference to `pcl::VoxelGrid<pcl::PointXYZRGBA>::applyFilter(pcl::PointCloud<pcl::PointXYZRGBA>&)'
../lib/libORB_SLAM2.so: undefined reference to `pcl::PCLBase<pcl::PointXYZRGBA>::initCompute()'
../lib/libORB_SLAM2.so: undefined reference to `pcl::PCLBase<pcl::PointXYZRGBA>::setInputCloud(boost::shared_ptr<pcl::PointCloud<pcl::PointXYZRGBA> const> const&)'
../lib/libORB_SLAM2.so: undefined reference to `pcl::PCLBase<pcl::PointXYZRGBA>::setIndices(boost::shared_ptr<pcl::PointIndices const> const&)'
collect2: error: ld returned 1 exit status
make[2]: *** [../Examples/RGB-D/rgbd_tum] Error 1
make[1]: *** [CMakeFiles/rgbd_tum.dir/all] Error 2
../lib/libORB_SLAM2.so: undefined reference to `pcl::PCLBase<pcl::PointXYZRGBA>::setIndices(boost::shared_ptr<std::vector<int, std::allocator<int> > const> const&)'
../lib/libORB_SLAM2.so: undefined reference to `pcl::PCLBase<pcl::PointXYZRGBA>::PCLBase()'
../lib/libORB_SLAM2.so: undefined reference to `pcl::PCLBase<pcl::PointXYZRGBA>::deinitCompute()'
../lib/libORB_SLAM2.so: undefined reference to `pcl::visualization::CloudViewer::showCloud(boost::shared_ptr<pcl::PointCloud<pcl::PointXYZRGBA> const> const&, std::string const&)'
../lib/libORB_SLAM2.so: undefined reference to `pcl::visualization::CloudViewer::~CloudViewer()'
../lib/libORB_SLAM2.so: undefined reference to `pcl::PCLBase<pcl::PointXYZRGBA>::setIndices(unsigned long, unsigned long, unsigned long, unsigned long)'
../lib/libORB_SLAM2.so: undefined reference to `pcl::visualization::CloudViewer::CloudViewer(std::string const&)'
../lib/libORB_SLAM2.so: undefined reference to `pcl::PCLBase<pcl::PointXYZRGBA>::setIndices(boost::shared_ptr<std::vector<int, std::allocator<int> > > const&)'
../lib/libORB_SLAM2.so: undefined reference to `pcl::VoxelGrid<pcl::PointXYZRGBA>::applyFilter(pcl::PointCloud<pcl::PointXYZRGBA>&)'
../lib/libORB_SLAM2.so: undefined reference to `pcl::PCLBase<pcl::PointXYZRGBA>::initCompute()'
../lib/libORB_SLAM2.so: undefined reference to `pcl::PCLBase<pcl::PointXYZRGBA>::setInputCloud(boost::shared_ptr<pcl::PointCloud<pcl::PointXYZRGBA> const> const&)'
../lib/libORB_SLAM2.so: undefined reference to `pcl::PCLBase<pcl::PointXYZRGBA>::setIndices(boost::shared_ptr<pcl::PointIndices const> const&)'
collect2: error: ld returned 1 exit status
make[2]: *** [../Examples/Monocular/mono_tum] Error 1
make[1]: *** [CMakeFiles/mono_tum.dir/all] Error 2
../lib/libORB_SLAM2.so: undefined reference to `pcl::PCLBase<pcl::PointXYZRGBA>::setIndices(boost::shared_ptr<std::vector<int, std::allocator<int> > const> const&)'
../lib/libORB_SLAM2.so: undefined reference to `pcl::PCLBase<pcl::PointXYZRGBA>::PCLBase()'
../lib/libORB_SLAM2.so: undefined reference to `pcl::PCLBase<pcl::PointXYZRGBA>::deinitCompute()'
../lib/libORB_SLAM2.so: undefined reference to `pcl::visualization::CloudViewer::showCloud(boost::shared_ptr<pcl::PointCloud<pcl::PointXYZRGBA> const> const&, std::string const&)'
../lib/libORB_SLAM2.so: undefined reference to `pcl::visualization::CloudViewer::~CloudViewer()'
../lib/libORB_SLAM2.so: undefined reference to `pcl::PCLBase<pcl::PointXYZRGBA>::setIndices(unsigned long, unsigned long, unsigned long, unsigned long)'
../lib/libORB_SLAM2.so: undefined reference to `pcl::visualization::CloudViewer::CloudViewer(std::string const&)'
../lib/libORB_SLAM2.so: undefined reference to `pcl::PCLBase<pcl::PointXYZRGBA>::setIndices(boost::shared_ptr<std::vector<int, std::allocator<int> > > const&)'
../lib/libORB_SLAM2.so: undefined reference to `pcl::VoxelGrid<pcl::PointXYZRGBA>::applyFilter(pcl::PointCloud<pcl::PointXYZRGBA>&)'
../lib/libORB_SLAM2.so: undefined reference to `pcl::PCLBase<pcl::PointXYZRGBA>::initCompute()'
../lib/libORB_SLAM2.so: undefined reference to `pcl::PCLBase<pcl::PointXYZRGBA>::setInputCloud(boost::shared_ptr<pcl::PointCloud<pcl::PointXYZRGBA> const> const&)'
../lib/libORB_SLAM2.so: undefined reference to `pcl::PCLBase<pcl::PointXYZRGBA>::setIndices(boost::shared_ptr<pcl::PointIndices const> const&)'
collect2: error: ld returned 1 exit status
make[2]: *** [../Examples/Stereo/stereo_euroc] Error 1
make[1]: *** [CMakeFiles/stereo_euroc.dir/all] Error 2
make: *** [all] Error 2

解决

CMakeLists.txt中加入以下内容:

find_package (PCL 1.8 REQUIRED)

set(PCL_INCLUDE_DIRS /usr/local/include/pcl-1.8)  #指定pcl1.8路径

add_definitions(${PCL_DEFINITIONS}) #暂时未使用到

include_directories( ... ${PCL_INCLUDE_DIRS})

target_link_libraries( ... ${PCL_LIBRARIES})
### 解决C++ PCL中的`undefined reference`链接错误 当在编译过程中遇到`undefined reference to pcl::`类似的错误时,这通常是由于链接无法找到某些类或函数的具体实现所引起的。具体来说,在使用PCL(Point Cloud Library)的过程中可能会碰到这样的问题。 对于`undefined reference to vtable for`类型的错误,这类错误通常发生在含有纯虚函数的基类中,表明存在未定义的虚函数表项[^1]。然而针对具体的`pcl::`命名空间下的符号解析失败,则更可能是因为以下几个原因: #### 1. 链接缺失必要的PCL模块 如果项目试图调用特定于某个子模块的功能却没有正确配置该模块的话,就会发生此类错误。例如尝试访问`pcl::visualization::PCLVisualizer`而忘记加入可视化组件的支持[^3]。 为了修正这一点,应该确认CMakeLists.txt文件里包含了所有需要用到的PCL模块,并通过适当的方式引入这些依赖关系。比如对于较新的PCL版本(>1.9),应当调整find_package指令来匹配当前环境的要求。 ```cmake find_package(PCL 1.10 REQUIRED COMPONENTS common io visualization) include_directories(${PCL_INCLUDE_DIRS}) link_directories(${PCL_LIBRARY_DIRS}) add_definitions(${PCL_DEFINITIONS}) target_link_libraries(your_project_name ${PCL_LIBRARIES}) ``` #### 2. 编译选项不一致 另一个常见问题是不同部分之间使用的编译参数有所差异,特别是涉及到调试模式(-g)或是优化级别(Ox)的选择上。确保整个工程都采用相同的设置可以有效减少这种冲突的可能性。 此外,还需注意是否启用了任何影响二进制兼容性的特性开关,如地址随机化布局(Relocation Read-Only, RPATH)等。 #### 3. 路径与版本管理不当 最后但同样重要的是要仔细检查系统的动态加载器能否顺利定位到所需的共享对象(.so/.dll)及其确切版本号。有时候即使安装了最新版的PCL包也可能因为旧版本残留而导致混淆;或者是跨平台移植时不当地硬编码绝对路径也会引发同样的麻烦。 可以通过运行`ldd your_executable | grep pcl`命令查看实际被加载的.so文件位置以及它们所属的具体发行版次。必要时更新系统上的PCL软件包至统一版本并清理掉多余的副本。 综上所述,解决上述提到的各种情况能够帮助消除大部分由`undefined reference`引起的问题。当然每种情形背后的原因不尽相同,因此建议逐一排查直至找出根本所在为止。
评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值