在阅读《PCL从入门到精通》这本书时,在第三章的las文件转换成pcd文件中。遇到下列问题,(所用系统为Ubuntu18.04):
在执行make时出现如下的错误
pcl@pcl-ROS:~/pclLearn/las2pcd$ make
[ 50%] Linking CXX executable bin/las2pcd
CMakeFiles/las2pcd.dir/las2pcd.cpp.o: In function `main':
las2pcd.cpp:(.text+0x84): undefined reference to `liblas::ReaderFactory::CreateWithStream(std::istream&)'
las2pcd.cpp:(.text+0x93): undefined reference to `liblas::Reader::GetHeader() const'
las2pcd.cpp:(.text+0x9b): undefined reference to `liblas::Header::GetPointRecordsCount() const'
las2pcd.cpp:(.text+0x111): undefined reference to `liblas::Reader::ReadNextPoint()'
las2pcd.cpp:(.text+0x128): undefined reference to `liblas::Reader::GetPoint() const'
las2pcd.cpp:(.text+0x130): undefined reference to `liblas::Point::GetX() const'
las2pcd.cpp:(.text+0x171): undefined reference to `liblas::Reader::GetPoint() const'
las2pcd.cpp:(.text+0x179): undefined reference to `liblas::Point::GetY() const'
las2pcd.cpp:(.text+0x1bb): undefined reference to `liblas::Reader::GetPoint() const'
las2pcd.cpp:(.text+0x1c3): undefined reference to `liblas::Point::GetZ() const'
las2pcd.cpp:(.text+0x205): undefined reference to `liblas::Reader::GetPoint() const'
las2pcd.cpp:(.text+0x21a): undefined reference to `liblas::Point::GetColor() const'
las2pcd.cpp:(.text+0x23f): undefined reference to `liblas::Reader::GetPoint() const'
las2pcd.cpp:(.text+0x254): undefined reference to `liblas::Point::GetColor() const'
las2pcd.cpp:(.text+0x279): undefined reference to `liblas::Reader::GetPoint() const'
las2pcd.cpp:(.text+0x28e): undefined reference to `liblas::Point::GetColor() const'
las2pcd.cpp:(.text+0x41c): undefined reference to `liblas::Reader::~Reader()'
las2pcd.cpp:(.text+0x49f): undefined reference to `liblas::Reader::~Reader()'
出现libLAS中的相关函数未定义。如果大家用的是随书代码中提供的libLAS的库,应该均会出现此问题。
这是因为随书源码是针对的Windows系统的,提供的库为Windows系统下的静态库和动态库。不适用在Ubuntu系统下。
解决方法:
我们需要自己下载libLAS库的源码进行编译:
1.下载源码:http://download.osgeo.org/liblas/libLAS-1.8.1.tar.bz2,我这里下载的是1.8.1版本的
2. 编译源码:cd libLAS-1.8.1
mkdir build
cd build
cmake ..
make
3.将~/libLAS-1.8.1/build/bin/Release目录下的*.so文件复制到las2pcd的源码中。编译运行即可。