pcl::io::savePCDFile 报错 “未定义的引用”

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/sunshinefcx/article/details/84135794

电脑平台:Ubuntu 16.04   64位

boost版本:1.58

pcl版本:1.7

g++/gcc版本:4.8(后改成5.0,才可以通过编译)

跟着做高翔的“一起做RGBD-SLAM“第三讲的时候,需要保存生成的点云图,在程序中使用的是下面的一条语句:

pcl::io::savePCDFile( "./data/pointcloud.pcd", *cloud);

但是在在cmake编译的时候 总会报错,报错信息如下:

[ 87%] Building CXX object src/CMakeFiles/generate_pointcloud.dir/generatePointCloud.cpp.o
[100%] Linking CXX executable ../../bin/generate_pointcloud
CMakeFiles/generate_pointcloud.dir/generatePointCloud.cpp.o:在函数‘pcl::PCDWriter::write(std::string const&, pcl::PCLPointCloud2 const&, Eigen::Matrix<float, 4, 1, 0, 4, 1> const&, Eigen::Quaternion<float, 0> const&, bool)’中:
generatePointCloud.cpp:(.text._ZN3pcl9PCDWriter5writeERKSsRKNS_14PCLPointCloud2ERKN5Eigen6MatrixIfLi4ELi1ELi0ELi4ELi1EEERKNS6_10QuaternionIfLi0EEEb[_ZN3pcl9PCDWriter5writeERKSsRKNS_14PCLPointCloud2ERKN5Eigen6MatrixIfLi4ELi1ELi0ELi4ELi1EEERKNS6_10QuaternionIfLi0EEEb]+0xc):对‘pcl::PCDWriter::writeASCII(std::string const&, pcl::PCLPointCloud2 const&, Eigen::Matrix<float, 4, 1, 0, 4, 1> const&, Eigen::Quaternion<float, 0> const&, int)’未定义的引用
generatePointCloud.cpp:(.text._ZN3pcl9PCDWriter5writeERKSsRKNS_14PCLPointCloud2ERKN5Eigen6MatrixIfLi4ELi1ELi0ELi4ELi1EEERKNS6_10QuaternionIfLi0EEEb[_ZN3pcl9PCDWriter5writeERKSsRKNS_14PCLPointCloud2ERKN5Eigen6MatrixIfLi4ELi1ELi0ELi4ELi1EEERKNS6_10QuaternionIfLi0EEEb]+0x11):对‘pcl::PCDWriter::writeBinary(std::string const&, pcl::PCLPointCloud2 const&, Eigen::Matrix<float, 4, 1, 0, 4, 1> const&, Eigen::Quaternion<float, 0> const&)’未定义的引用
CMakeFiles/generate_pointcloud.dir/generatePointCloud.cpp.o:在函数‘int pcl::PCDWriter::writeASCII<pcl::PointXYZRGBA>(std::string const&, pcl::PointCloud<pcl::PointXYZRGBA> const&, int)’中:
generatePointCloud.cpp:(.text._ZN3pcl9PCDWriter10writeASCIIINS_12PointXYZRGBAEEEiRKSsRKNS_10PointCloudIT_EEi[_ZN3pcl9PCDWriter10writeASCIIINS_12PointXYZRGBAEEEiRKSsRKNS_10PointCloudIT_EEi]+0xd5):对‘pcl::PCDWriter::setLockingPermissions(std::string const&, boost::interprocess::file_lock&)’未定义的引用
generatePointCloud.cpp:(.text._ZN3pcl9PCDWriter10writeASCIIINS_12PointXYZRGBAEEEiRKSsRKNS_10PointCloudIT_EEi[_ZN3pcl9PCDWriter10writeASCIIINS_12PointXYZRGBAEEEiRKSsRKNS_10PointCloudIT_EEi]+0x78e):对‘pcl::PCDWriter::resetLockingPermissions(std::string const&, boost::interprocess::file_lock&)’未定义的引用
CMakeFiles/generate_pointcloud.dir/generatePointCloud.cpp.o:在函数‘int pcl::PCDWriter::writeBinary<pcl::PointXYZRGBA>(std::string const&, pcl::PointCloud<pcl::PointXYZRGBA> const&)’中:
generatePointCloud.cpp:(.text._ZN3pcl9PCDWriter11writeBinaryINS_12PointXYZRGBAEEEiRKSsRKNS_10PointCloudIT_EE[_ZN3pcl9PCDWriter11writeBinaryINS_12PointXYZRGBAEEEiRKSsRKNS_10PointCloudIT_EE]+0xf0):对‘pcl::PCDWriter::setLockingPermissions(std::string const&, boost::interprocess::file_lock&)’未定义的引用
generatePointCloud.cpp:(.text._ZN3pcl9PCDWriter11writeBinaryINS_12PointXYZRGBAEEEiRKSsRKNS_10PointCloudIT_EE[_ZN3pcl9PCDWriter11writeBinaryINS_12PointXYZRGBAEEEiRKSsRKNS_10PointCloudIT_EE]+0x516):对‘pcl::PCDWriter::resetLockingPermissions(std::string const&, boost::interprocess::file_lock&)’未定义的引用
generatePointCloud.cpp:(.text._ZN3pcl9PCDWriter11writeBinaryINS_12PointXYZRGBAEEEiRKSsRKNS_10PointCloudIT_EE[_ZN3pcl9PCDWriter11writeBinaryINS_12PointXYZRGBAEEEiRKSsRKNS_10PointCloudIT_EE]+0x73c):对‘pcl::PCDWriter::resetLockingPermissions(std::string const&, boost::interprocess::file_lock&)’未定义的引用
generatePointCloud.cpp:(.text._ZN3pcl9PCDWriter11writeBinaryINS_12PointXYZRGBAEEEiRKSsRKNS_10PointCloudIT_EE[_ZN3pcl9PCDWriter11writeBinaryINS_12PointXYZRGBAEEEiRKSsRKNS_10PointCloudIT_EE]+0x7ca):对‘pcl::PCDWriter::resetLockingPermissions(std::string const&, boost::interprocess::file_lock&)’未定义的引用
generatePointCloud.cpp:(.text._ZN3pcl9PCDWriter11writeBinaryINS_12PointXYZRGBAEEEiRKSsRKNS_10PointCloudIT_EE[_ZN3pcl9PCDWriter11writeBinaryINS_12PointXYZRGBAEEEiRKSsRKNS_10PointCloudIT_EE]+0x8b5):对‘pcl::PCDWriter::resetLockingPermissions(std::string const&, boost::interprocess::file_lock&)’未定义的引用
generatePointCloud.cpp:(.text._ZN3pcl9PCDWriter11writeBinaryINS_12PointXYZRGBAEEEiRKSsRKNS_10PointCloudIT_EE[_ZN3pcl9PCDWriter11writeBinaryINS_12PointXYZRGBAEEEiRKSsRKNS_10PointCloudIT_EE]+0x94e):对‘pcl::PCDWriter::resetLockingPermissions(std::string const&, boost::interprocess::file_lock&)’未定义的引用
collect2: error: ld returned 1 exit status
src/CMakeFiles/generate_pointcloud.dir/build.make:437: recipe for target '../bin/generate_pointcloud' failed
make[2]: *** [../bin/generate_pointcloud] Error 1
CMakeFiles/Makefile2:202: recipe for target 'src/CMakeFiles/generate_pointcloud.dir/all' failed
make[1]: *** [src/CMakeFiles/generate_pointcloud.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

排查过程:

猜测1:怀疑   src/CMakeLists.txt  中对pcl 的引用方式有错

   在Ubuntu14.04中,不需要添加修复指令,但是在Ubuntu 16.04中,需要在  src/CMakeLists.txt  中添加一条修复指令,详见如下:

# 增加PCL库的依赖
FIND_PACKAGE( PCL REQUIRED COMPONENTS common io visualization )

list(REMOVE_ITEM PCL_LIBRARIES "vtkproj4") # use this in Ubuntu 16.04

# 添加头文件和库文件
ADD_DEFINITIONS( ${PCL_DEFINITIONS} )
INCLUDE_DIRECTORIES( ${PCL_INCLUDE_DIRS}  )
LINK_LIBRARIES( ${PCL_LIBRARY_DIRS} )

list(REMOVE_ITEM PCL_LIBRARIES "vtkproj4") # use this in Ubuntu 16.04

标红的这句 就是修复指令。但是写上还是不行

猜测2:pcl安装有问题

先从高翔的github上下载了源程序,里面有已经生成的pointcloud.pcd文件,假如说pcl库没有安装好,那么是打不开点云图的,所以就进入到pointcloud.pcd所在的文件夹下面,命令如下:

pcl_viewer pointcloud.pcd 

结果,出来点云图了,说明安装的pcl库是没问题的

猜测3:g++/gcc 的版本不对

在之前安装opencv3的时候,也遇到过”未定义的引用“这类的问题,当时是我电脑上g++/gcc的版本是5.0,降低到4.8版本之后,才完成了opencv3的安装,之后也没有改回来。所以抱着试试的态度,把g++/gcc版本改回来

修改方法,参考我的另一篇:Ubuntu中g++ gcc安装及版本切换

修改到5.0版本之后,再次编译,结果  就通过编译了!!!

简直太开心了!!!感谢我乖宝滴陪伴~程序员  永不认输!!!

猜你喜欢

转载自blog.csdn.net/sunshinefcx/article/details/84135794