安装环境
cmake版本:cmake-3.26.3-windows-x86_64
pcl版本:PCL 1.13.1
vs版本:vs2022
配置流程
cmake编译准备:新建两个文件夹source和cmake_bin。source用于存放.cpp文件和CMakeLists.txt
文件;cmake_bin存放配置生成结果
.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 (auto& point: cloud)
{
point.x = 1024 * rand () / (RAND_MAX + 1.0f);
point.y = 1024 * rand () / (RAND_MAX + 1.0f);
point.z = 1024 * rand () / (RAND_MAX + 1.0f);
}
pcl::io::savePCDFileASCII ("test_pcd.pcd", cloud);
std::cerr << "Saved " << cloud.size () << " data points to test_pcd.pcd." << std::endl;
for (const auto& point: cloud)
std::cerr << " " << point.x << " " << point.y << " " << point.z << std::endl;
return (0);
}
CMakeLists.txt
文件内容:
cmake_minimum_required(VERSION 3.23 FATAL_ERROR)
project(MY_GRAND_PROJECT)
find_package(PCL 1.13.1 REQUIRED COMPONENTS common io)
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
add_executable(pcd_write_test main.cpp)
target_link_libraries(pcd_write_test ${PCL_LIBRARIES})
注意版本名,项目名和文件名要对应
打开CMake,配置好文件夹的路径
点击configure,弹出下面的消息框
点击Finish,然后再点generate。
点击【Open Project】按钮,然后将pcd_write_test,
设置为启动项,再点击运行即可
最后生成的结果为:
参考:[windows]Visual studio 2019下使用Cmake配置PCL