Cmake
在这里我使用的是vscode+cmke+pcl
文章目录
- Cmake
- 前言
- 一、安装PCL
- 二、安装与配置Cmake与PCL
- [三 验证有没有安装成功](#三 验证有没有安装成功)
前言
记录自己学习PCL的过程
一、安装PCL
powershell
我喜欢命令行导入:
brew install pcl
如果下载的很慢:
vim ~/.zshrc
# Homebrew 镜像源加速配置
export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.ustc.edu.cn/brew.git"
export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.ustc.edu.cn/homebrew-core.git"
export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.ustc.edu.cn/homebrew-bottles"
export HOMEBREW_API_DOMAIN="https://mirrors.ustc.edu.cn/homebrew-bottles/api"
source ~/.zshrc
brew update
brew install pcl(再重新导入pcl)
bash
用来验证有没有安装好pcl
pkg-config --modversion pcl_common
如果出现类似1.15.1这样的数字恭喜你安装成功了
二、安装与配置Cmake与PCL
bash
# 先更新 Homebrew 的软件列表,确保能获取到最新版本
brew update
# 安装 CMake
brew install cmake
cmake --version(用来验证安装)
步骤 1:安装 VSCode 扩展
打开 VSCode
点击左侧的扩展图标(或按 Cmd+Shift+X)
搜索并安装 CMake Tools(作者:Microsoft)
步骤 2:打开你的项目
在 VSCode 中打开你 的项目文件夹(如果你还没有CMakeLists.txt这个文件,需要自己创建,不会自己生成)
cpp
这里面就是CMakeLists.txt文件的配置
cmake_minimum_required(VERSION 3.10)
project(cpp_total_project)
# 查找 PCL 库
find_package(PCL 1.5 REQUIRED)
# 添加头文件路径
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
# 创建可执行文件(把 main.cpp 改成你的源文件名)
add_executable(my_program test.cpp)
# 链接 PCL 库
target_link_libraries(my_program ${PCL_LIBRARIES})
步骤 3:配置项目
按 Cmd+Shift+P,输入 CMake: Configure 并选择
或者直接按 F7 键
VSCode 会自动检测到 CMake 并开始配置
bash
大概你的文件夹就是这样
├── CMakeLists.txt ← 需要修改这个文件
├── main.cpp ← 你的源代码文件(或其他名字)
└── build/ ← 已经自动生成了
步骤 4:编译项目
配置完成后,按 F7 再次编译
或者点击底部状态栏的 Build 按钮

三 验证有没有安装成功
cpp
#include <iostream>
#include "pcl/io/pcd_io.h"
#include "pcl/point_types.h"
int
main (int argc, char** argv)
{
pcl::PointCloud<pcl::PointXYZ> cloud;
// Fill in the cloud data
cloud.width = 5;
cloud.height = 1;
cloud.is_dense = false;
cloud.points.resize (cloud.width * cloud.height);
for (size_t i = 0; i < cloud.points.size (); ++i)
{
cloud.points[i].x = 1024 * rand () / (RAND_MAX + 1.0f);
cloud.points[i].y = 1024 * rand () / (RAND_MAX + 1.0f);
cloud.points[i].z = 1024 * rand () / (RAND_MAX + 1.0f);
}
pcl::io::savePCDFileASCII ("test_pcd.pcd", cloud);
std::cerr << "Saved " << cloud.points.size () << " data points to test_pcd.pcd." << std::endl;
for (size_t i = 0; i < cloud.points.size (); ++i)
std::cerr << " " << cloud.points[i].x << " " << cloud.points[i].y << " " << cloud.points[i].z << std::endl;
return (0);
}
结果如下
cpp
Saved 5 data points to test_pcd.pcd.
0.0080142 0.694695 -0.26015
-0.342265 -0.446349 0.214207
0.173687 -0.84253 -0.400481
-0.874475 0.706127 -0.117635
0.908514 -0.598159 0.744714