Ubuntu20.04下liblas的CMakelists编写

在《点云库PCL从入门到精通》中的第三章的第5个案例有代码和CMakelists.txt.但是进行cmake的时候一直报错,如下:

[ 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()'

根据 https://blog.csdn.net/qq_41900369/article/details/122022641 这篇文章老哥的说法,是因为随书源码是针对的Windows系统的,提供的库为Windows系统下的静态库和动态库。不适用在Ubuntu系统下。但是该文章的解决方案,我照着作了,还是无法解决,继续报这个错

本人C++小白,所以真的不太懂,琢磨了好久,网上的方法也都无法解决
但是吧,最后阴差阳错的被我解决了,下面是我的CMakelists.txt的内容:

cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
project(las2pcd)

find_package(PCL 1.2 REQUIRED)
find_package(libLAS REQUIRED)

include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})

**include_directories("/usr/local/include/liblas/")
link_directories("/usr/local/lib")**

add_executable (las2pcd las2pcd.cpp)

**target_link_libraries (las2pcd ${PCL_LIBRARIES} "/usr/local/lib/liblas.so.2.4.0")**

重要的就是加**的那三句了,其路径根据自己的路径可能需要修改一下

哦对了,我是先源码编译安装了liblas库的,其步骤如下:
1、下载源码:http://download.osgeo.org/liblas/libLAS-1.8.1.tar.bz2
2、编译源码:
cd libLAS-1.8.1
mkdir build
cd build
cmake …
make
sudo make install (这一步很重要哦!我一开始就漏了这步)

以上。

文章出处登录后可见!

已经登录?立即刷新

共计人评分,平均

到目前为止还没有投票!成为第一位评论此文章。

(0)
xiaoxingxing的头像xiaoxingxing管理团队
上一篇 2022年6月13日
下一篇 2022年6月13日

相关推荐