在ubuntu上安装配置pcl的时候踩了不少坑,最后使用vscode+cmake搞定了整套流程。
完整的正确流程如下:
这里参考这篇博文:https://blog.csdn.net/weixin_46474546/article/details/104711901
下载(https://download.qt.io/archive/qt/5.12/5.12.6/qt-opensource-linux-x64-5.12.6.run)
下载文件夹下运行
chmod +x qt-opensource-linux-x64-5.12.6.run
./qt-opensource-linux-x64-5.12.6.run
安装的时候记住要安装全部的Qt文件,只勾选开发工具是不可以的
下载tar.gz包(https://www.vtk.org/files/release/7.1/VTK-7.1.1.tar.gz)
安装X11,openGL,CMake
sudo apt-get install libx11-dev libxext-dev libxtst-dev libxrender-dev libxmu-dev libxmuu-dev
sudo apt-get install build-essential libgl1-mesa-dev libglu1-mesa-dev
sudo apt-get install cmake cmake-qt-gui
VTK-7.1.1.tar.gz
,在VTK-7.1.1文件夹中建立build文件夹/VTK-7.1.1
。设置“where to build the binaries:”为工程生成的目录/VTK-7.1.1/build
(手动新建一个)“VTK_GROUP_Qt”
选项,再次点击“Configure”按钮,提示警告信息,需要设置Qt5安装路径VTK_QT_VERSION
选择 “5”
再次点击“Configure”按钮Qt5_DIR
设置路径为QT的安装目录 /opt/Qt5.12.6/5.12.6/gcc_64/lib/cmake/Qt5
在build目录中运行下面的命令
sudo make
sudo make install
Boost,Eigen,FlANN,VTK,OpenNI,QHull,metslib
等第三方库:sudo apt-get install libflann1.8 libflann-dev
sudo apt-get install libeigen3-dev
sudo apt-get install libboost-all-dev
sudo apt-get install cmake cmake-qt-gui libusb-1.0-0-dev libusb-dev libudev-dev mpi-default-dev openmpi-bin openmpi-common libqhull* libgtest-dev freeglut3-dev pkg-config libxmu-dev libxi-dev mono-complete libopenni-dev libopenni2-dev libpng-dev
sudo apt-get install libpcap-dev
sudo apt-get install libglew-dbg libglew-dev libglew1.13 libglewmx-dbg libglewmx-dev libglewmx1.13 glew-utils
sudo apt-get install libqhull*
metslib
库:wget http://www.coin-or.org/download/source/metslib/metslib-0.5.3.tgz
tar zxvf metslib-0.5.3.tgz
cd metslib-0.5.3
./configure
make
sudo apt-get install autoconf automake libtool
sudo make install
下载pcl文件(https://github.com/PointCloudLibrary/pcl/archive/refs/tags/pcl-1.9.1.tar.gz),如果有网络问题建议在网上找同名包
解压并进入解压出的PCL-1.9.1
文件夹,运行
mkdir build && cd build
cmake -D CMAKE_BUILD_TYPE=None -D BUILD_GPU=ON -D BUILD_apps=ON -D BUILD_examples=ON ..
sudo make
sudo make install
参考:http://vegetable.wodekouwei.com/2019/04/21/l-cmake-syntax/
默认已经完成了vscode以及插件的安装
建立如下的文件结构,其中.vscode和build是文件夹
.
├── .vscode
├──├──c_cpp_properties.json
├──├──launch.json
├──├──tasks.json
├── build
├── CMakeLists.txt
└── pcl_test.cpp
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"/usr/include",
"/usr/local/include"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64",
"compileCommands": "${workspaceFolder}/build/compile_commands.json"
}
],
"version": 4
}
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/pcl_test",// 表示可执行程序所在的路径,其中,${workspaceRoot}表示VScode加载的文件夹的根目录
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "make build"
}
]
}
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "make build",//编译的项目名,build
"type": "shell",
"command": "cd ./build ;cmake ../ -DCMAKE_EXPORT_COMPILE_COMMANDS=1 ;make",//编译命令
"group": {
"kind": "build",
"isDefault": true
}
},
{
"label": "clean",
"type": "shell",
"command": "make clean",
}
]
}
cmake_minimum_required(VERSION 2.6)
project(pcl_test)
find_package(PCL 1.9 REQUIRED)
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
add_executable(pcl_test pcl_test.cpp)
target_link_libraries (pcl_test ${PCL_LIBRARIES})
install(TARGETS pcl_test RUNTIME DESTINATION bin)
#include
#include
#include
#include
int user_data;
void
viewerOneOff (pcl::visualization::PCLVisualizer& viewer)
{
viewer.setBackgroundColor (1.0, 0.5, 1.0);
pcl::PointXYZ o;
o.x = 1.0;
o.y = 0;
o.z = 0;
viewer.addSphere (o, 0.25, "sphere", 0);
std::cout << "i only run once" << std::endl;
}
void
viewerPsycho (pcl::visualization::PCLVisualizer& viewer)
{
static unsigned count = 0;
std::stringstream ss;
ss << "Once per viewer loop: " << count++;
viewer.removeShape ("text", 0);
viewer.addText (ss.str(), 200, 300, "text", 0);
//FIXME: possible race condition here:
user_data++;
}
int
main ()
{
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);
pcl::io::loadPCDFile ("cat.pcd", *cloud);
pcl::visualization::CloudViewer viewer("Cloud Viewer");
//blocks until the cloud is actually rendered
viewer.showCloud(cloud);
//use the following functions to get access to the underlying more advanced/powerful
//PCLVisualizer
//This will only get called once
viewer.runOnVisualizationThreadOnce (viewerOneOff);
//This will get called once per visualization iteration
viewer.runOnVisualizationThread (viewerPsycho);
while (!viewer.wasStopped ())
{
//you can also do cool processing here
//FIXME: Note that this is running in a separate thread from viewerPsycho
//and you should guard against race conditions yourself...
user_data++;
}
return 0;
}