当前位置:   article > 正文

PCL学习1:mac下PCL的安装与配置_/opt/homebrew/include/pcl-1.14/pcl/pcl_macros.h:37

/opt/homebrew/include/pcl-1.14/pcl/pcl_macros.h:375:14: fatal error: mm_mall

PCL
PCL官方文档

PCL(Point Cloud Library)是在吸收了前人点云相关研究基础上建立起来的大型跨平台开源C++编程库,它实现了大量点云相关的通用算法和高效数据结构,涉及到点云获取、滤波、分割、配准、检索、特征提取、识别、追踪、曲面重建、可视化等。支持多种操作系统平台,可在Windows、Linux、Android、Mac OS X、部分嵌入式实时系统上运行。如果说OpenCV是2D信息获取与处理的结晶,那么PCL就在3D信息获取与处理上具有同等地位,PCL是BSD授权方式,可以免费进行商业和学术应用。


  1. 第一步:安装homebrew

homebrew的介绍和安装步骤详情见如下链接:
Homebrew的介绍和使用
mac安装配置homebrew

实际上只需要打开终端,输入:

ruby -e "$(curl --insecure -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" 
  • 1

接下来等待安装完毕即可

  1. 使用homebrew安装pcl

也很简单,打开终端,输入:

brew install pcl
  • 1

首先会安装PCL的相关依赖库,如vtk,glew等,最后安装pcl

  1. PCL的编译

这一步是最麻烦的,由于之前更多地在Windows上进行开发,更没有接触过cmake,所以碰到了许多稀奇古怪的问题。

官方给出的编译方案:

Using PCL in your own project

第一步:在工程目录下(如Desktop/PCLtest/)新建文件CMakeLists.txt,在该文件中写入:

cmake_minimum_required(VERSION 2.6 FATAL_ERROR) # 选择cmake版本
project(PCLtest) # 给工程命名
find_package(PCL 1.3 REQUIRED COMPONENTS common io) # 使用find_package寻找指定版本PCL的指定模块,如果想导入全部模块,也可以写为 find_package(PCL REQUIRED) include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
add_executable(PCLtest main.cpp)
target_link_libraries(PCLtest ${PCL_LIBRARIES})
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

第二步:在工程目录下新建文件main.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);
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30

第三步:在工程目录下新建build文件夹

cd /PATH/TO/MY/GRAND/PROJECT
mkdir build
  • 1
  • 2

第四步:打开终端,进行编译

cd build
cmake ..
make
  • 1
  • 2
  • 3

cmake后屏幕输出:

/Applications/CLion.app/Contents/bin/cmake/mac/bin/cmake -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - Unix Makefiles" /Users/zhi/Desktop/PCLtest
-- The C compiler identification is AppleClang 10.0.1.10010046
-- The CXX compiler identification is AppleClang 10.0.1.10010046
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Checking for module 'eigen3'
--   Found eigen3, version 3.3.7
-- Found Eigen: /usr/local/include/eigen3  
-- Eigen found (include: /usr/local/include/eigen3, version: 3.3.7)
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - found
-- Found Threads: TRUE  
-- Boost version: 1.70.0
-- Found the following Boost libraries:
--   system
--   filesystem
--   thread
--   date_time
--   iostreams
--   serialization
--   chrono
--   atomic
--   regex
-- Checking for module 'flann'
--   Found flann, version 1.9.1
-- FLANN found (include: /usr/local/Cellar/flann/1.9.1_7/include, lib: flann;flann_cpp)
-- FLANN found (include: /usr/local/Cellar/flann/1.9.1_7/include, lib: flann;flann_cpp)
** WARNING ** io features related to pcap will be disabled
** WARNING ** io features related to png will be disabled
-- Found libusb-1.0: /usr/local/include  
** WARNING ** io features related to libusb-1.0 will be disabled
-- Found Qhull: optimized;/usr/local/lib/libqhull_p.dylib;debug;/usr/local/lib/libqhull_p.dylib  
-- QHULL found (include: /usr/local/include, lib: optimized;/usr/local/lib/libqhull_p.dylib;debug;/usr/local/lib/libqhull_p.dylib)
-- Found OpenGL: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/OpenGL.framework   
-- Found PkgConfig: /usr/local/bin/pkg-config (found version "0.29.2") 
-- Checking for module 'glew'
--   Found glew, version 2.1.0
-- Found Glew: GLEW;-framework Cocoa
-- looking for PCL_COMMON
-- Found PCL_COMMON: /usr/local/lib/libpcl_common.dylib  
-- looking for PCL_KDTREE
-- Found PCL_KDTREE: /usr/local/lib/libpcl_kdtree.dylib  
-- looking for PCL_OCTREE
-- Found PCL_OCTREE: /usr/local/lib/libpcl_octree.dylib  
-- looking for PCL_SEARCH
-- Found PCL_SEARCH: /usr/local/lib/libpcl_search.dylib  
-- looking for PCL_SAMPLE_CONSENSUS
-- Found PCL_SAMPLE_CONSENSUS: /usr/local/lib/libpcl_sample_consensus.dylib  
-- looking for PCL_FILTERS
-- Found PCL_FILTERS: /usr/local/lib/libpcl_filters.dylib  
-- looking for PCL_2D
-- Found PCL_2D: /usr/local/include/pcl-1.9  
-- looking for PCL_GEOMETRY
-- Found PCL_GEOMETRY: /usr/local/include/pcl-1.9  
-- looking for PCL_IO
-- Found PCL_IO: /usr/local/lib/libpcl_io.dylib  
-- looking for PCL_FEATURES
-- Found PCL_FEATURES: /usr/local/lib/libpcl_features.dylib  
-- looking for PCL_ML
-- Found PCL_ML: /usr/local/lib/libpcl_ml.dylib  
-- looking for PCL_SEGMENTATION
-- Found PCL_SEGMENTATION: /usr/local/lib/libpcl_segmentation.dylib  
-- looking for PCL_VISUALIZATION
-- Found PCL_VISUALIZATION: /usr/local/lib/libpcl_visualization.dylib  
-- looking for PCL_SURFACE
-- Found PCL_SURFACE: /usr/local/lib/libpcl_surface.dylib  
-- looking for PCL_REGISTRATION
-- Found PCL_REGISTRATION: /usr/local/lib/libpcl_registration.dylib  
-- looking for PCL_KEYPOINTS
-- Found PCL_KEYPOINTS: /usr/local/lib/libpcl_keypoints.dylib  
-- looking for PCL_TRACKING
-- Found PCL_TRACKING: /usr/local/lib/libpcl_tracking.dylib  
-- looking for PCL_RECOGNITION
-- Found PCL_RECOGNITION: /usr/local/lib/libpcl_recognition.dylib  
-- looking for PCL_STEREO
-- Found PCL_STEREO: /usr/local/lib/libpcl_stereo.dylib  
-- looking for PCL_APPS
-- Found PCL_APPS: /usr/local/lib/libpcl_apps.dylib  
-- looking for PCL_OUTOFCORE
-- Found PCL_OUTOFCORE: /usr/local/lib/libpcl_outofcore.dylib  
-- looking for PCL_PEOPLE
-- Found PCL_PEOPLE: /usr/local/lib/libpcl_people.dylib  
-- looking for PCL_SIMULATION
-- Found PCL_SIMULATION: /usr/local/lib/libpcl_simulation.dylib  
-- Found PCL: pcl_common;pcl_kdtree;pcl_octree;pcl_search;pcl_sample_consensus;pcl_filters;pcl_io;pcl_features;pcl_ml;pcl_segmentation;pcl_visualization;pcl_surface;pcl_registration;pcl_keypoints;pcl_tracking;pcl_recognition;pcl_stereo;pcl_apps;pcl_outofcore;pcl_people;pcl_simulation;/usr/local/lib/libboost_system-mt.dylib;/usr/local/lib/libboost_filesystem-mt.dylib;/usr/local/lib/libboost_thread-mt.dylib;/usr/local/lib/libboost_date_time-mt.dylib;/usr/local/lib/libboost_iostreams-mt.dylib;/usr/local/lib/libboost_serialization-mt.dylib;/usr/local/lib/libboost_chrono-mt.dylib;/usr/local/lib/libboost_atomic-mt.dylib;/usr/local/lib/libboost_regex-mt.dylib;optimized;/usr/local/lib/libqhull_p.dylib;debug;/usr/local/lib/libqhull_p.dylib;flann;flann_cpp;vtksys;vtkCommonCore;vtkCommonMath;vtkCommonMisc;vtkCommonSystem;vtkCommonTransforms;vtkCommonDataModel;vtkCommonColor;vtkCommonExecutionModel;vtkCommonComputationalGeometry;vtkFiltersCore;vtkFiltersGeneral;vtkImagingCore;vtkImagingFourier;vtkFiltersStatistics;vtkFiltersExtraction;vtkInfovisCore;vtkFiltersGeometry;vtkFiltersSources;vtkRenderingCore;/usr/lib/libz.dylib;vtkfreetype;vtkRenderingFreeType;vtkRenderingContext2D;vtkChartsCore;vtkDICOMParser;vtkdoubleconversion;vtklz4;vtklzma;vtkIOCore;vtkIOLegacy;/usr/lib/libexpat.dylib;vtkIOXMLParser;vtkDomainsChemistry;vtkglew;vtkRenderingOpenGL2;vtkDomainsChemistryOpenGL2;vtkIOXML;vtkParallelCore;vtkFiltersAMR;vtkFiltersFlowPaths;vtkFiltersGeneric;vtkImagingSources;vtkFiltersHybrid;vtkFiltersHyperTree;vtkImagingGeneral;vtkFiltersImaging;vtkFiltersModeling;vtkFiltersParallel;vtkFiltersParallelImaging;vtkFiltersPoints;vtkFiltersProgrammable;/usr/local/opt/python/Frameworks/Python.framework/Versions/3.7/Python;vtkPythonInterpreter;vtkWrappingTools;vtkWrappingPythonCore;vtkFiltersPython;vtkFiltersSMP;vtkFiltersSelection;vtkFiltersTexture;vtkFiltersTopology;verdict;vtkFiltersVerdict;vtkInteractionStyle;vtkGUISupportQt;vtksqlite;vtkIOSQL;vtkGUISupportQtSQL;vtkmetaio;/usr/local/lib/libjpeg.dylib;/usr/local/lib/libpng.dylib;/usr/local/lib/libtiff.dylib;vtkIOImage;vtkImagingHybrid;vtkInfovisLayout;vtkImagingColor;vtkRenderingAnnotation;vtkRenderingVolume;vtkInteractionWidgets;vtkViewsCore;vtklibproj;vtkGeovisCore;/usr/local/lib/libhdf5.dylib;/usr/local/lib/libsz.dylib;/usr/lib/libdl.dylib;/usr/lib/libm.dylib;/usr/local/lib/libhdf5_hl.dylib;vtkIOAMR;vtkIOAsynchronous;vtkpugixml;vtkIOCityGML;vtkIOEnSight;/usr/local/lib/libnetcdf.dylib;vtkexodusII;vtkIOExodus;vtkgl2ps;vtkRenderingGL2PSOpenGL2;vtkIOExport;vtkIOExportOpenGL2;vtklibharu;vtkIOExportPDF;vtkIOGeometry;vtkIOImport;/usr/lib/libxml2.dylib;vtkIOInfovis;vtkIOLSDyna;vtkIOMINC;vtkogg;vtktheora;vtkIOMovie;vtkIONetCDF;vtkIOPLY;vtkjsoncpp;vtkIOParallel;vtkIOParallelXML;vtkIOSegY;vtkIOTecplotTable;vtkIOVeraOut;vtkIOVideo;vtkImagingMath;vtkImagingMorphological;vtkImagingStatistics;vtkImagingStencil;vtkInfovisBoostGraphAlgorithms;vtkInteractionImage;vtkPythonContext2D;vtkRenderingContextOpenGL2;vtkRenderingFreeTypeFontConfig;vtkRenderingImage;vtkRenderingLOD;vtkRenderingLabel;vtkRenderingQt;vtkRenderingVolumeOpenGL2;vtkViewsContext2D;vtkViewsInfovis;vtkViewsQt  
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/zhi/Desktop/PCLtest/cmake-build-debug
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100

make后输出:

Scanning dependencies of target PCLtest
[ 50%] Building CXX object CMakeFiles/PCLtest.dir/main.cpp.o
[100%] Linking CXX executable PCLtest
[100%] Built target PCLtest
  • 1
  • 2
  • 3
  • 4

编译成功后,运行工程:

./pcd_write_test
  • 1

运行结果:

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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  1. 使用CLion配置PCL

打开CLion新建工程,工程自动给出CMakeLists.txt和main.cpp,在对应文件中写入内容后运行即可

配置过程中出现的各种奇怪问题

  1. 在编译前检查是否安装cmake,若没有安装,直接brew install cmake即可
  2. 尽量使用gcc进行编译,若没有安装,直接brew install gcc(亲身验证,使用clang也可以。。。在编译过程中一直出现错误,病急乱投医,一度认为是编译器的问题)
  3. 由于mac默认c编译器为clang,如果想使用gcc编译,参考:CMake 指定gcc编译版本
export CC=/usr/local/bin/gcc #你的gcc编译器路径
export CXX=/usr/local/bin/g++
cmake /path/to/your/project
make
  • 1
  • 2
  • 3
  • 4
  1. 整个过程中最烦心的错误出现了,搜索全网都没有找到与我出现相同错误的同学!!此时cmake是成功的,但是在make时提示出现错误:
Scanning dependencies of target pcd_write_test
[ 50%] Building CXX object CMakeFiles/pcd_write_test.dir/pcd_write.cpp.o
make[2]: *** No rule to make target `/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/Python', needed by `pcd_write_test'.  Stop.
make[1]: *** [CMakeFiles/pcd_write_test.dir/all] Error 2
make: *** [all] Error 2
  • 1
  • 2
  • 3
  • 4
  • 5

解决方案(非常粗暴)找到文件夹/usr/local/Cellar/python/,发现里面只有一个文件夹3.7.4,直接将其文件夹名称改为3.7.3,问题解决

  1. 提示:simulation is required but glew was not found
    原因在于simulation模块需要glew的支持,但没有找到
    解决方案:更加粗暴,直接在PCLConfig.cmake中直接把搜索glew模块的语句注释掉(因为我不需要该模块,只求编译通过,需要调用该模块的同学慎用)
find_package(PCL 1.3 REQUIRED COMPONENTS common io) 
  • 1
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/花生_TL007/article/detail/518402
推荐阅读
相关标签
  

闽ICP备14008679号