在进行科研项目时,我们常常需要将 C++ 和 Python 结合起来编程。然而,每次将 PCL(Point Cloud Library)的内容添加到 CMakeLists.txt 文件中时都会报错。在深入分析后,我们推测可能是当前使用的 PCL 1.8 版本与现有程序不兼容。因此,我们决定尝试安装最新的 PCL 1.14.1 版本,以期望解决这些兼容性问题。
1. 卸载旧版本的 PCL:
首先,我们需要卸载系统中现有的 PCL 1.8 版本,以避免与新版本产生冲突。
sudo apt-get remove libpcl-dev
2. 安装依赖
sudo apt-get update
sudo apt-get install git build-essential linux-libc-dev
sudo apt-get install cmake cmake-gui
sudo apt-get install libusb-1.0-0-dev libusb-dev libudev-dev
sudo apt-get install mpi-default-dev openmpi-bin openmpi-common
sudo apt-get install libflann1.9 libflann-dev #这里改成1.9
sudo apt-get install libeigen3-dev
sudo apt-get install libboost-all-dev
sudo apt-get install libvtk7.1-qt libvtk7.1 libvtk7-qt-dev # 这里用7.1 不要用8以上的
sudo apt-get install libqhull* libgtest-dev
sudo apt-get install freeglut3-dev pkg-config
sudo apt-get install libxmu-dev libxi-dev
sudo apt-get install mono-complete
sudo apt-get install openjdk-8-jdk openjdk-8-jre# 安装OpenNI,OpenNI2
sudo apt-get install libopenni-dev
sudo apt-get install libopenni2-dev# 安装QT5:
sudo apt install qtcreator
sudo apt install qt5-default# 安装metslib
wget https://www.coin-or.org/download/source/metslib/metslib-0.5.3.tgz
tar xzvf metslib-0.5.3.tgz
cd metslib-0.5.3
./configure
make -j`nproc`
sudo make install
中间提示选择Y/N的全部选Y
3.下载最新版本的PCL库并编译
git clone https://github.com/PointCloudLibrary/pcl.git 或者git clone https://gitee.com/mirrors/pcl.git
如果需要指定版本,请你点击下面连接进行下载。
Releases · PointCloudLibrary/pcl · GitHubPoint Cloud Library (PCL). Contribute to PointCloudLibrary/pcl development by creating an account on GitHub.https://github.com/PointCloudLibrary/pcl/releases例如:
选择source.zip
解压进入 pcl 文件夹:
cd pcl
# 切换到指定版本v1.14.1再编译
# git checkout pcl-1.14.1 # 也可以不要这一行命令,直接安装最新的版本
# 创建目录并进入目录
mkdir build && cd build#安装在系统目录
cmake .. \-DCMAKE_BUILD_TYPE=None \-DCMAKE_INSTALL_PREFIX=/usr/local \-DCMAKE_PREFIX_PATH=/usr/lib/x86_64-linux-gnu \-DFREETYPE_LIBRARY=/usr/lib/x86_64-linux-gnu/libfreetype.so \-DBUILD_GPU=ON \-DBUILD_apps=ON \-DBUILD_simulation=ON \-DBUILD_examples=ON#也可以安装在自己指定的目录,如下所示(主要是改下安装空间):
cmake .. \-DCMAKE_BUILD_TYPE=None \-DCMAKE_INSTALL_PREFIX=~/Programs/lib/PCL1141 \-DCMAKE_PREFIX_PATH=/usr/lib/x86_64-linux-gnu \-DFREETYPE_LIBRARY=/usr/lib/x86_64-linux-gnu/libfreetype.so \-DBUILD_GPU=ON \-DBUILD_apps=ON \-DBUILD_simulation=ON \-DBUILD_examples=ON# Orin 切换到 MAXN POWER MODE
# 进行编译
make -j`nproc`#编译完后,执行安装
sudo make install
make -j`nproc`成功界面
sudo make install 成功界面
问题1:
/usr/bin/ld: warning: //home/fairlee/anaconda3/lib/libicudata.so.73: unsupported GNU_PROPERTY_TYPE (5) type: 0xc0010001
/usr/bin/ld: warning: //home/fairlee/anaconda3/lib/libicudata.so.73: unsupported GNU_PROPERTY_TYPE (5) type: 0xc0010002
//home/fairlee/anaconda3/lib/libfontconfig.so.1: undefined reference to `FT_Done_MM_Var'
collect2: error: ld returned 1 exit status
tools/CMakeFiles/pcl_pcd_grabber_viewer.dir/build.make:170: recipe for target 'bin/pcl_pcd_grabber_viewer' failed
make[2]: *** [bin/pcl_pcd_grabber_viewer] Error 1
CMakeFiles/Makefile2:3197: recipe for target 'tools/CMakeFiles/pcl_pcd_grabber_viewer.dir/all' failed
make[1]: *** [tools/CMakeFiles/pcl_pcd_grabber_viewer.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
解决方案:
这个错误可能是由于系统中存在多个版本的库,而编译器使用了不兼容的版本。在这种情况下,Anaconda环境中的库可能与系统库冲突。因此,完全移除Anaconda的影响: 临时重命名你的Anaconda目录,以确保系统不会使用任何Anaconda的库:
最后安装成功后,别忘了把文件名改回去!!!!!!!!!
4. 安装验证
CMakeLists.txt
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
project(pcl_version_check)# 设置C++标准
set(CMAKE_CXX_STANDARD 14)# 查找PCL包
find_package(PCL REQUIRED)# 添加PCL的头文件路径
include_directories(${PCL_INCLUDE_DIRS})# 添加PCL的库路径
link_directories(${PCL_LIBRARY_DIRS})# 添加编译选项
add_definitions(${PCL_DEFINITIONS})# 添加可执行文件
add_executable(pcl_version_check pcl_version_check.cpppcl_version_check.cpp)# 链接PCL库
target_link_libraries(pcl_version_check ${PCL_LIBRARIES})
pcl_version_check.cpp
#include <iostream>
#include <pcl/pcl_config.h>
#include <pcl/point_types.h>
#include <pcl/point_cloud.h>
#include <iostream>
#include <pcl/common/common_headers.h>
#include <pcl/io/pcd_io.h>
#include <pcl/visualization/pcl_visualizer.h>
#include <pcl/visualization/cloud_viewer.h>
#include <pcl/console/parse.h>int main() {std::cout << "PCL version: " << PCL_VERSION_PRETTY << std::endl;// 创建一个简单的点云对象来测试基本功能pcl::PointCloud<pcl::PointXYZ> cloud;std::cout << "Test PCL !" << std::endl;pcl::PointCloud<pcl::PointXYZRGB>::Ptr point_cloud_ptr (new pcl::PointCloud<pcl::PointXYZRGB>);uint8_t r(255), g(15), b(15);for (float z(-1.0); z <= 1.0; z += 0.05) {for (float angle(0.0); angle <= 360.0; angle += 5.0) {pcl::PointXYZRGB point;point.x = 0.5 * cosf (pcl::deg2rad(angle));point.y = sinf (pcl::deg2rad(angle));point.z = z;uint32_t rgb = (static_cast<uint32_t>(r) << 16 | static_cast<uint32_t>(g) << 8 | static_cast<uint32_t>(b));point.rgb = *reinterpret_cast<float*>(&rgb);point_cloud_ptr->points.push_back (point);}if (z < 0.0) {r -= 12;g += 12;}else {g -= 12;b += 12;}}point_cloud_ptr->width = (int) point_cloud_ptr->points.size ();point_cloud_ptr->height = 1;pcl::visualization::CloudViewer viewer ("test");viewer.showCloud(point_cloud_ptr);while (!viewer.wasStopped()){ };// 如果代码执行到这里没有错误,说明PCL基本功能正常std::cout << "PCL basic functionality test passed." << std::endl;return 0;
}
结果
致谢
ubuntu 18.04 安装PCL 1.12.1_the following subsystems will not be built:-- visu-CSDN博客