关于CMake(cmake-gui)的使用及注意事项,超详细!
该教程只只适用于安装好了vs以及pcl,我是在visual studio2022里面根据指示安装的cmake,而visual studio安装过程官网很详细,这里就不再啰嗦了。
1.cmake是一个编译工具,能够输出相应的project,首先打开cmake-gui:
2.要输出project,需要对应的源码和CMakeLists.txt编译规则文件。首先创建一个项目文件test,暂且放在桌面,将源码和CMakeLists.txt文件放入文件夹。
3.在打开的cmake-gui中,上方的where is the source code是源码位置,链接进test位置即可,像上面图片一样,下面是输出文件位置,我们在test文件夹下面建立一个新的文件夹build,把build位置复制进去即可。
4.这里给一个测试pcl的代码pcl_test.cpp。
#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(int argc, char **argv) { 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()){ }; return 0; }
这里是CMakeLists.txt文件内容:
cmake_minimum_required(VERSION 2.6) project(pcl_test) find_package(PCL 1.2 REQUIRED) include_directories(${PCL_INCLUDE_DIRS}) link_directories(${PCL_LIBRARY_DIRS}) add_definitions(${PCL_DEFINITIONS}) add_executable(pcl_test pcl_test.cpp) target_link_libraries (pcl_test ${PCL_LIBRARIES}) install(TARGETS pcl_test RUNTIME DESTINATION bin)
这里要注意了:CMakeLists.txt文件里面的可执行文件,即源码,名称一定要和上面创建的源码一样。
5.点击configure,根据你安装的visual studio版本和位数选择第一项和第二项,如下图:
6.点击Finish,等待生成,如下:
7.点击Generate,ok了。
8.点击Open Project,进入visual studio
9.右键点击项目pcl_test,选择设为启动项,不然程序运行会显示:拒绝访问:
10.运行结果如下:
over。
下一篇:
Java四类八种数据类型