Compiling PCL on RPI3

PCL, or Point Cloud Library, is an open-source library of algorithms for point cloud processing tasks, such as computer vision and 3D imaging. Unfortunately, the command “sudo apt-get install libpcl-all” doesn’t particularly work in some instances. Whether that is the case or you’re just curious and want to learn, here is a step by step guide to compiling PCL on RPI3.

First off, this process requires many pre-requisites and a lot of time. Courtesy of Mr. Li, he has a blog that I will be referencing, which you can find here:

  1.  Before getting to the PCL compiling pre-requisites, run the following commands
sudo add-apt-repository ppa:v-launchpad-jochen-sprickerhof-de/pcl
sudo apt-get update
sudo apt-get install libusb-1.0-0-dev libudev-dev linux-libc-dev

Note: You may get an error concerning that the system is unable to lock the administration directory after entering “sudo apt-get update”. While there is a method to delete the lock file, simply just reboot the system and run the command again.

  1.  Now, run all of the following commands (pre-requisites). The first two lines are if you do not have git installed on your machine, as git is used in the next line to clone the PCL repository.
sudo apt-get update
sudo apt-get install git
git clone pcl-trunk
ln -s pcl-trunk pcl
sudo apt-get install g++
sudo apt-get install cmake cmake-gui
sudo apt-get install doxygen
sudo apt-get install mpi-default-dev openmpi-bin openmpi-common  
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 libvtk5.10-qt4 libvtk5.10 libvtk5-dev
sudo apt-get install libqhull*
sudo apt-get install libusb-dev
sudo apt-get install libgtest-dev
sudo apt-get install git-core freeglut3-dev pkg-config
sudo apt-get install build-essential libxmu-dev libxi-dev 
sudo apt-get install libusb-1.0-0-dev graphviz mono-complete
sudo apt-get install qt-sdk openjdk-8-jdk openjdk-8-jre
  1.  Change the directory to the PCL source directory (which can be done by entering “cd pcl” if you are in the home directory). Enter the following commands to compile PCL by using cmake.**
mkdir release
cd release

**WARNING: Before running the “make” command, you must create a swap file or else the compiler will restrict itself and kill the process. A swap file is essentially space on the storage device that is used as a virtual memory extension of the computer’s RAM. Quite useful in compiling massive projects that push the limits of your RAM. Here are the steps to do so:

  1. First, check that there is no active swap by entering the command “free -h”. Also make sure you are in the home directory (enter “cd”).
  2. For the purposes of compiling PCL, we will create a 2 GB swap file. The size of the file can be modified later. Run the following commands:
sudo fallocate -l 2G /swapfile
ls -lh /swapfile           →This is to check that the file is indeed 2GB
sudo chmod 600 /swapfile   →Make the file only accessible to root
sudo mkswap /swapfile      →Identifies the file as swap space
sudo swapon /swapfile      →Enables swap file
sudo swapon --show         → Verifies that the swap file is working

—–The following commands are to make the swap file permanent—–

sudo cp /etc/fstab /etc/fstab.bak            
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
  1. With the swap file in place, you can now run “make” to compile PCL without a hitch. The process will take approx. 7 hours, so feel free to leave the compiler running while you do something else, or perhaps overnight. Once PCL is done compiling, install it by running the last command:
sudo make install

Congratulations, you have compiled PCL from source and installed it on your RPI3 machine!