PCL Point Cloud Library Tutorial (Part 2): IDE Selection and CMake Usage

PCL Point Cloud Library Tutorial (Part 2): IDE Selection and CMake Usage

Introduction

PCL Point Cloud Library Tutorial (Part 2): IDE Selection and CMake Usage
Last Issue Review:
[PCL Point Cloud Library Tutorial (Part 1)] Installation and Prerequisites
PCL Point Cloud Library Tutorial (Part 2): IDE Selection and CMake Usage

You can switch the target files we need to compile. Click the “hammer” icon to compile, and click the “triangle” icon to compile and run.

PCL Point Cloud Library Tutorial (Part 2): IDE Selection and CMake Usage
PCL Point Cloud Library Tutorial (Part 2): IDE Selection and CMake Usage

Computer Environment

PCL Point Cloud Library Tutorial (Part 2): IDE Selection and CMake Usage
  • Ubuntu 20.04
  • PCL-1.10

VS Code

PCL Point Cloud Library Tutorial (Part 2): IDE Selection and CMake Usage
PCL Point Cloud Library Tutorial (Part 2): IDE Selection and CMake Usage

Reasons for Recommendation

PCL Point Cloud Library Tutorial (Part 2): IDE Selection and CMake Usage

Lightweight, many plugins, stronger customization.

Many people may not know how to compile and run C++ with VS Code, while Visual Studio 2019 is too intelligent, users do not need to write CMakeLists.txt, but it only supports C++ development on Windows. Writing C++ in VS Code has a certain threshold, so I will share my experience with you; basic usage should be fine.

PCL Point Cloud Library Tutorial (Part 2): IDE Selection and CMake Usage

Create Project

PCL Point Cloud Library Tutorial (Part 2): IDE Selection and CMake Usage

Execute the following in the terminal:

mkdir PCL_study # Create a new foldercd PCL_study/mkdir build # For storing executable filesmkdir src # For storing C++ files touch CMakeLists.txt # For adding compilation files, libraries, etc.cd build/cmake ..

The above process is equivalent to creating a project.

Write c_cpp_properties.json

To have code suggestions and jump to header files, you need to configure the path of the PCL library in VS Code.

After opening the project folder, press Ctrl + Shift + P in VS Code to display the input box, input configurations, and it will look like this:

PCL Point Cloud Library Tutorial (Part 2): IDE Selection and CMake Usage

Click the first option, which will generate a new folder and a new file:

PCL Point Cloud Library Tutorial (Part 2): IDE Selection and CMake Usage

Add the installation path of PCL and the path of Eigen3 (a matrix computation library often used in PCL) as follows (first ensure that your PCL is installed at that path):

PCL Point Cloud Library Tutorial (Part 2): IDE Selection and CMake Usage
Write CMakeLists.txt

Create a cpp file in the src folder; here I will create a main.cpp file.

cmake_minimum_required(VERSION 3.5 FATAL_ERROR) project(PCL_study) find_package(PCL 1.7 REQUIRED) include_directories(${PCL_INCLUDE_DIRS}) link_directories(${PCL_LIBRARY_DIRS}) add_definitions(${PCL_DEFINITIONS}) find_package(Eigen3 REQUIRED) include_directories(${EIGEN3_INCLUDE_DIRS}) link_directories(${EIGEN3_LIBRARY_DIRS}) add_executable(main src/main.cpp) target_link_libraries(main ${PCL_LIBRARIES} ${EIGEN3_LIBRARIES})
PCL Point Cloud Library Tutorial (Part 2): IDE Selection and CMake Usage

Next, you can write code in main.cpp.

PCL Point Cloud Library Tutorial (Part 2): IDE Selection and CMake Usage

Compile and Run

PCL Point Cloud Library Tutorial (Part 2): IDE Selection and CMake Usage

Create a new terminal:

PCL Point Cloud Library Tutorial (Part 2): IDE Selection and CMake Usage

Compile the program to generate the executable file:

cd build/ # Enter directorycmake .. # Generate Makefilemake -j8 # Compile (my CPU is 4 cores 8 threads, so I choose j8, multi-threading can speed up compilation)
PCL Point Cloud Library Tutorial (Part 2): IDE Selection and CMake Usage

Run the program:

./main
PCL Point Cloud Library Tutorial (Part 2): IDE Selection and CMake Usage

CLion

PCL Point Cloud Library Tutorial (Part 2): IDE Selection and CMake Usage
PCL Point Cloud Library Tutorial (Part 2): IDE Selection and CMake Usage

JetBrains IDEs are great!!!

Reasons for Recommendation

Compared to many of you who have used PyCharm, CLion is a smart C++ IDE from the same company. Educational email accounts can be used for free registration and download, and it supports multiple platforms. Compared to VS Code, it is more intelligent and everyone who has used it says it’s good.

Create Project

PCL Point Cloud Library Tutorial (Part 2): IDE Selection and CMake Usage

CLion automatically generates some files for us:

PCL Point Cloud Library Tutorial (Part 2): IDE Selection and CMake Usage

Among them, cmake-build-debug is equivalent to the previous build folder.

To keep the folders organized, create a new src folder under the project and move main.cpp into it. The modified directory structure is as follows:

PCL Point Cloud Library Tutorial (Part 2): IDE Selection and CMake Usage
Write CMakeLists.txt

In CLion, you do not need to configure c_cpp_properties.json; CLion can find the path of the PCL library by itself.

PCL Point Cloud Library Tutorial (Part 2): IDE Selection and CMake Usage

Every time you modify CMakeLists.txt, make sure to click the “Reload changes” button at the top right to refresh the loading; otherwise, you will not be able to compile and run the new cpp files we added.

PCL Point Cloud Library Tutorial (Part 2): IDE Selection and CMake Usage

Here you can switch the target files we need to compile. Click the “hammer” icon to compile, and click the “triangle” icon to compile and run.

You can also compile and run the program in the terminal at the bottom of the IDE like in VS Code.

PCL Point Cloud Library Tutorial (Part 2): IDE Selection and CMake Usage
PCL Point Cloud Library Tutorial (Part 2): IDE Selection and CMake Usage
PCL Point Cloud Library Tutorial (Part 2): IDE Selection and CMake Usage
PCL Point Cloud Library Tutorial (Part 2): IDE Selection and CMake Usage

“MoveIt! Mastering Dual-Arm Robots • Li Jianghao”

Leading everyone to design a dual-arm robot based on MoveIt!, while also designing a teaching handwheel and developing the corresponding ROS package for controlling the robotic arm in the ROS system. This tutorial is still a course that combines software and hardware development; once you make a dual-arm robot, you can also play with a single-arm robot.

PCL Point Cloud Library Tutorial (Part 2): IDE Selection and CMake Usage

(Scan to view course details)
PCL Point Cloud Library Tutorial (Part 2): IDE Selection and CMake Usage
PCL Point Cloud Library Tutorial (Part 2): IDE Selection and CMake Usage

Click “Read More” to join the study

Leave a Comment