PCL1.9的PCLConfig.cmake文件找不到eigen等外部依赖

PCL1.9的PCLConfig.cmake文件找不到eigen等外部依赖

由于需要用到PCL中on_nurbs模块做拟合,但是ros自带的pcl中没有该模块。所以源码安装了PCL 1.9,但是在使用过程中遇到了如下问题。

1. 安装过程

1.安装如下依赖项

sudo apt-get update
sudo apt-get install git build-essential linux-libc-dev
sudo apt-get install cmake cmake-gui
sudo apt-get install libusb-1.0-0-dev libusb-dev libudev-dev
sudo apt-get install mpi-default-dev openmpi-bin openmpi-common
sudo apt-get install libflann1.8 libflann-dev
sudo apt-get install libeigen3-dev
sudo apt-get install libboost-all-dev
#sudo apt-get install libvtk5.10-qt4 libvtk5.10 libvtk5-dev //会卸载ros安装的部分软件包
#sudo apt-get install libqhull* libgtest-dev//安装不了,改成下一句命令
sudo apt-get install libgtest-dev libqhull-dev libqhull-doc
sudo apt-get install freeglut3-dev pkg-config 
sudo apt-get install libxmu-dev libxi-dev
sudo apt-get install mono-complete 
sudo apt-get install qt-sdk openjdk-8-jdk openjdk-8-jre

但是在安装vtk5.10库文件的时候会删除ros中的相关文件,所以跳过了该命令。

下载PCL源代码

git clone https://github.com/PointCloudLibrary/pcl.git

下载过程更换成手机热点,从而达到高速下载速度。

3、编译安装

ls
cd pcl
mkdir release
cd release 
 cmake -DCMAKE_BUILD_TYPE=None -DCMAKE_INSTALL_PREFIX=/usr \ -DBUILD_GPU=ON -DBUILD_apps=ON -DBUILD_examples=ON \ -DCMAKE_INSTALL_PREFIX=/usr ..
make -j8  
sudo make install

4、如果需要PCLVisualizer,安装OpenNI、OpenNI2

sudo apt-get install libopenni-dev 
sudo apt-get install libopenni2-dev

2. PCLConfig.cmake文件找不到eigen等外部依赖

在将PCL成功编译安装之后,在项目的CMakeLists.txt中文件中添加如下语句,用于添加PCL相关库文件:

set(PCL_DIR /home/Andy/my_workspace/pcl-master/release)
find_package(PCL REQUIRED COMPONENTS)
find_package(Eigen3 REQUIRED)
list(REMOVE_ITEM PCL_LIBRARIES "vtkproj4")

include_directories( ${PCL_INCLUDE_DIRS} )
link_directories(${PCL_LIBRARY_DIRS})
add_definitions( ${PCL_DEFINITIONS} )

但是在 cmake的过程中会提示出现如下问题:

By not providing "FindEigen.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "Eigen", but
  CMake did not find one.

  Could not find a package configuration file provided by "Eigen" (requested
  version 3.1) with any of the following names:

    EigenConfig.cmake
    eigen-config.cmake

  Add the installation prefix of "Eigen" to CMAKE_PREFIX_PATH or set
  "Eigen_DIR" to a directory containing one of the above files.  If "Eigen"
  provides a separate development package or SDK, be sure it has been
  installed.
Call Stack (most recent call first):
  /home/Andy/my_workspace/pcl-master/release/PCLConfig.cmake:314 (find_eigen)
  /home/Andy/my_workspace/pcl-master/release/PCLConfig.cmake:547 (find_external_library)
  CMakeLists.txt:32 (find_package)


CMake Error at /home/Andy/my_workspace/pcl-master/release/PCLConfig.cmake:60 (message):
  common is required but eigen was not found
Call Stack (most recent call first):
  /home/Andy/my_workspace/pcl-master/release/PCLConfig.cmake:365 (pcl_report_not_found)
  /home/Andy/my_workspace/pcl-master/release/PCLConfig.cmake:547 (find_external_library)
  CMakeLists.txt:32 (find_package)


-- Configuring incomplete, errors occurred!
See also "/home/Andy/my_workspace/Code/Clion_code/PCL_example/PCL_Curve_Fitting/build/CMakeFiles/CMakeOutput.log".
See also "/home/Andy/my_workspace/Code/Clion_code/PCL_example/PCL_Curve_Fitting/build/CMakeFiles/CMakeError.log".

产生这个问题的原因在于PCLConfig.cmake文件找不到eigen依赖。
可以将PCLConfig.cmake文件中的find_eigen函数改为如下形式:

macro(find_eigen)
  if(PCL_ALL_IN_ONE_INSTALLER)
    set(EIGEN_ROOT "${PCL_ROOT}/3rdParty/Eigen")
  elseif(NOT EIGEN_ROOT)
    get_filename_component(EIGEN_ROOT "/usr/include/eigen3" ABSOLUTE)
  endif(PCL_ALL_IN_ONE_INSTALLER)
  if(PKG_CONFIG_FOUND)
    pkg_check_modules(PC_EIGEN eigen3)
  endif(PKG_CONFIG_FOUND)
  find_path(EIGEN_INCLUDE_DIRS Eigen/Core
    HINTS ${PC_EIGEN_INCLUDEDIR} ${PC_EIGEN_INCLUDE_DIRS} 
          "${EIGEN_ROOT}" "$ENV{EIGEN_ROOT}"
    PATHS "$ENV{PROGRAMFILES}/Eigen 3.0.0" "$ENV{PROGRAMW6432}/Eigen 3.0.0"
          "$ENV{PROGRAMFILES}/Eigen" "$ENV{PROGRAMW6432}/Eigen"   
    PATH_SUFFIXES eigen3 include/eigen3 include)
  find_package_handle_standard_args(eigen DEFAULT_MSG EIGEN_INCLUDE_DIRS)
  set(EIGEN_DEFINITIONS ${EIGEN_DEFINITIONS} -DEIGEN_USE_NEW_STDVECTOR 
      -DEIGEN_YES_I_KNOW_SPARSE_MODULE_IS_NOT_STABLE_YET)
endmacro()

修改之后,重新编译还有报错,提示找不到OpenNIConfig.cmake。同理需要将PCLConfig.cmake文件中相应的函数进行修改。

改完之后,将成功编译。

完整的PCLConfig.cmake我以上传。可以直接下载,替换掉原来的PCLConfig.cmake文件。
PCLConfig.cmake

你可能感兴趣的:(C++)