内容简介
本文主要分享我在Ubuntu下安装PCL点云库的经验,这里我用的ubuntu是22.04版本,依赖库基本都下载的新的,VTK版本是8.2(建议不要使用更新版本),PCL版本是1.12.1。
安装ubuntu
这里建议安装虚拟机,可以参照ubuntu20.04安装教程进行安装,需要注意的是安装时候要分配足够的磁盘空间,因为如果后面扩展磁盘空间的话会比较麻烦,扩展硬盘空间可以参照扩展磁盘进行操作,建议不要走到这一步。
VMware全屏下不完全显示
这里参考VMware虚拟机不能全屏的解决办法进行操作,也就是将设置中的分辨率改一下。
换国内镜像源
有了ubuntu之后首先要做的就是换上国内的镜像源,这里可以参照Ubuntu换源的两种方法进行操作,这样能使我们的下载速度得到明显提升。
安装VTK
这里参照Ubuntu18安装VTK8.2进行操作,但是make时候出现了问题。
问题一
[ 87%] Linking C shared library ../../../lib/libvtkexodusII-8.2.so
/usr/bin/ld: CMakeFiles/vtkexodusII.dir/src/ex_open_par.c.o:/home/littlez/下载/Software/VTK-8.2.0/ThirdParty/exodusII/vtkexodusII/src/ex_open_par.c:477: multiple definition of `exodus_unused_symbol_dummy_1'; CMakeFiles/vtkexodusII.dir/src/ex_create_par.c.o:/home/littlez/下载/Software/VTK-8.2.0/ThirdParty/exodusII/vtkexodusII/src/ex_create_par.c:617: first defined here
collect2: error: ld returned 1 exit status
make[2]: *** [ThirdParty/exodusII/vtkexodusII/CMakeFiles/vtkexodusII.dir/build.make:4436:lib/libvtkexodusII-8.2.so.1] 错误 1
make[1]: *** [CMakeFiles/Makefile2:5836:ThirdParty/exodusII/vtkexodusII/CMakeFiles/vtkexodusII.dir/all] 错误 2
make: *** [Makefile:136:all] 错误 2
可以看到这是multiple definition of ‘exodus_unused_symbol_dummy_1’,处理办法也是简单粗暴,找到其中一个定义,然后注释掉。
问题二
[ 99%] Building CXX object Rendering/Qt/CMakeFiles/vtkRenderingQt.dir/vtkQtLabelRenderStrategy.cxx.o
/home/littlez/下载/Software/VTK-8.2.0/Rendering/Qt/vtkQtLabelRenderStrategy.cxx: In member function ‘virtual void vtkQtLabelRenderStrategy::ComputeLabelBounds(vtkTextProperty*, vtkUnicodeString, double*)’:
/home/littlez/下载/Software/VTK-8.2.0/Rendering/Qt/vtkQtLabelRenderStrategy.cxx:229:18: error: aggregate ‘QPainterPath path’ has incomplete type and cannot be defined
229 | QPainterPath path;
| ^~~~
/home/littlez/下载/Software/VTK-8.2.0/Rendering/Qt/vtkQtLabelRenderStrategy.cxx: In member function ‘virtual void vtkQtLabelRenderStrategy::RenderLabel(int*, vtkTextProperty*, vtkUnicodeString, int)’:
/home/littlez/下载/Software/VTK-8.2.0/Rendering/Qt/vtkQtLabelRenderStrategy.cxx:331:16: error: aggregate ‘QPainterPath path’ has incomplete type and cannot be defined
331 | QPainterPath path;
| ^~~~
/home/littlez/下载/Software/VTK-8.2.0/Rendering/Qt/vtkQtLabelRenderStrategy.cxx: In member function ‘virtual void vtkQtLabelRenderStrategy::RenderLabel(int*, vtkTextProperty*, vtkUnicodeString)’:
/home/littlez/下载/Software/VTK-8.2.0/Rendering/Qt/vtkQtLabelRenderStrategy.cxx:442:18: error: aggregate ‘QPainterPath path’ has incomplete type and cannot be defined
442 | QPainterPath path;
| ^~~~
make[2]: *** [Rendering/Qt/CMakeFiles/vtkRenderingQt.dir/build.make:104:Rendering/Qt/CMakeFiles/vtkRenderingQt.dir/vtkQtLabelRenderStrategy.cxx.o] 错误 1
make[1]: *** [CMakeFiles/Makefile2:7066:Rendering/Qt/CMakeFiles/vtkRenderingQt.dir/all] 错误 2
make: *** [Makefile:136:all] 错误 2
以及
[ 99%] Building CXX object Rendering/Qt/CMakeFiles/vtkRenderingQt.dir/vtkQtStringToImage.cxx.o
/home/littlez/下载/Software/VTK-8.2.0/Rendering/Qt/vtkQtStringToImage.cxx: In member function ‘virtual vtkVector2i vtkQtStringToImage::GetBounds(vtkTextProperty*, const vtkUnicodeString&, int)’:
/home/littlez/下载/Software/VTK-8.2.0/Rendering/Qt/vtkQtStringToImage.cxx:109:16: error: aggregate ‘QPainterPath path’ has incomplete type and cannot be defined
109 | QPainterPath path;
| ^~~~
/home/littlez/下载/Software/VTK-8.2.0/Rendering/Qt/vtkQtStringToImage.cxx: In member function ‘virtual vtkVector2i vtkQtStringToImage::GetBounds(vtkTextProperty*, const vtkStdString&, int)’:
/home/littlez/下载/Software/VTK-8.2.0/Rendering/Qt/vtkQtStringToImage.cxx:140:16: error: aggregate ‘QPainterPath path’ has incomplete type and cannot be defined
140 | QPainterPath path;
| ^~~~
/home/littlez/下载/Software/VTK-8.2.0/Rendering/Qt/vtkQtStringToImage.cxx: In member function ‘virtual int vtkQtStringToImage::RenderString(vtkTextProperty*, const vtkUnicodeString&, int, vtkImageData*, int*)’:
/home/littlez/下载/Software/VTK-8.2.0/Rendering/Qt/vtkQtStringToImage.cxx:187:16: error: aggregate ‘QPainterPath path’ has incomplete type and cannot be defined
187 | QPainterPath path;
| ^~~~
make[2]: *** [Rendering/Qt/CMakeFiles/vtkRenderingQt.dir/build.make:118:Rendering/Qt/CMakeFiles/vtkRenderingQt.dir/vtkQtStringToImage.cxx.o] 错误 1
make[1]: *** [CMakeFiles/Makefile2:7066:Rendering/Qt/CMakeFiles/vtkRenderingQt.dir/all] 错误 2
make: *** [Makefile:136:all] 错误 2
这里就是aggregate ‘QPainterPath path’ has incomplete type and cannot be defined 处理办法也是简单地在对应文件中加入
#includ <QPainterPath>
这样算是能完成编译,后续如有问题还会更新。
安装PCL
接下来要做的就是安装PCL了,这里可以参照ubuntu18.04 安装pcl(详细教程)进行操作,目前还没遇到问题,能完成下载,后续使用一段时间后再来分享。这里有条命令分享一下:
sudo apt-cache search libxxx
在编译VTK和PCL时我们一般会用多线程同时编译以节省时间,也就是
make -j2
然而这也会带来很大的内存开销,当内存不足时,make就会闪退,以我的实际经历来说,给了虚拟机8G内存,开两个线程make,结果还是会内存爆掉,只开一个线程才能正常make过去。
配置vscode
配置C++环境可以参照vscode环境中配置C++环境,配置PCL则可以参照vscode配置OpenCV+PCL进行操作。
不知什么原因根据上面“VScode配置PCL”没能实现,这里还是用cmake来编译,可以参考PCL配置,这里也简单介绍一下。
就是先在工程的文件夹中新建一个CMakeLists.txt,内容根据自己的需要来填,如:
cmake_minimum_required(VERSION 3.0)
project(testpcl)
find_package(PCL 1.2 REQUIRED)
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
add_executable(testpcl testpcl.cpp)
target_link_libraries (testpcl ${PCL_LIBRARIES})
install(TARGETS testpcl RUNTIME DESTINATION bin)
然后在终端中依次输入:
mkdir build
cd build
cmake ..
make
./testpcl #注意这里要根据实际填写
这样能完成编译并执行生成的可执行程序,这里在执行可执行文件的时候还遇到了一个问题。
littlez@littlez-virtual-machine:~/Learn/build$ ./testpcl
./testpcl: error while loading shared libraries: libvtkfreetype-8.2.so.1: cannot open shared object file: No such file or directory
这里参照解决可执行文件运行时报错及export LD_LIBRARY_PATH 的使用里的内容,在 ~ 路径下的 .bashrc 文件中加入下面语句
export LD_LIBRARY_PATH=LD_LIBRARY_PATH:/usr/local/lib
这样就能正常执行可执行文件了,以下是测试结果。
总结
泪目了,家人们!
这里要说的就是,make时候心中默念“佛祖保佑”,这样可以给cmake加buff(不是)。遇到困难不要怕,微笑地面对她!如果真地遇到问题,要相信我所走过的坑前人一定都走过,细心一点,看是报了什么错,然后去搜答案抄作业。如果真遇到了前人没踩过的坑,那就勇于做第一个踩坑人吧~~~
以上内容希望能给各位提供一定参考,最后祝各位都能successful !!!
|