Ubuntu 20.04无法找到PCL,因为在通过“sudo apt install libpcl-dev”安装后包含目录不正确

93ze6v8z  于 2023-01-25  发布在  其他
关注(0)|答案(1)|浏览(479)

操作系统:Ubuntu
PCL信息:

Package: libpcl-dev
Version: 1.10.0+dfsg-5ubuntu1
Priority: extra
Section: universe/libdevel
Source: pcl
Origin: Ubuntu

我通过sudo apt install libpcl-dev安装了PCL,并像这样使用它:

cmake_minimum_required(VERSION 3.5)
project(test)

# Default to C99
if(NOT CMAKE_C_STANDARD)
  set(CMAKE_C_STANDARD 99)
endif()

# Default to C++14
if(NOT CMAKE_CXX_STANDARD)
  set(CMAKE_CXX_STANDARD 14)
endif()

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  add_compile_options(-Wall -Wextra -Wpedantic -Wno-unused-parameter)
endif()

# find dependencies
find_package(PCL REQUIRED)

生成项目时出现一些错误:

CMake Error at /lib/x86_64-linux-gnu/cmake/pcl/PCLConfig.cmake:62 (message):
  PCL can not be found on this machine
Call Stack (most recent call first):
  /lib/x86_64-linux-gnu/cmake/pcl/PCLConfig.cmake:452 (pcl_report_not_found)
  CMakeLists.txt:37 (find_package)

-- Configuring incomplete, errors occurred!

我正在尝试调试/lib/x86_64-linux-gnu/cmake/pcl/PCLConfig.cmake:418-454中的cmake源代码,cmake源代码如下所示:

find_package(PkgConfig QUIET)

file(TO_CMAKE_PATH "${PCL_DIR}" PCL_DIR)
if(WIN32 AND NOT MINGW)
# PCLConfig.cmake is installed to PCL_ROOT/cmake
  get_filename_component(PCL_ROOT "${PCL_DIR}" PATH)
else()
# PCLConfig.cmake is installed to PCL_ROOT/share/pcl-x.y
  get_filename_component(PCL_ROOT "${CMAKE_CURRENT_LIST_DIR}/../../../.." ABSOLUTE)
endif()

# check whether PCLConfig.cmake is found into a PCL installation or in a build tree
if(EXISTS "${PCL_ROOT}/include/pcl-${PCL_VERSION_MAJOR}.${PCL_VERSION_MINOR}/pcl/pcl_config.h")
  # Found a PCL installation
  # pcl_message("Found a PCL installation")
  set(PCL_CONF_INCLUDE_DIR "${PCL_ROOT}/include/pcl-${PCL_VERSION_MAJOR}.${PCL_VERSION_MINOR}")
  set(PCL_LIBRARY_DIRS "${PCL_ROOT}/lib/x86_64-linux-gnu")
  if(EXISTS "${PCL_ROOT}/3rdParty")
    set(PCL_ALL_IN_ONE_INSTALLER ON)
  endif()
elseif(EXISTS "${PCL_ROOT}/include/pcl/pcl_config.h")
  # Found a non-standard (likely ANDROID) PCL installation
  # pcl_message("Found a PCL installation")
  set(PCL_CONF_INCLUDE_DIR "${PCL_ROOT}/include")
  set(PCL_LIBRARY_DIRS "${PCL_ROOT}/lib")
  if(EXISTS "${PCL_ROOT}/3rdParty")
    set(PCL_ALL_IN_ONE_INSTALLER ON)
  endif()
elseif(EXISTS "${PCL_DIR}/include/pcl/pcl_config.h")
  # Found PCLConfig.cmake in a build tree of PCL
  # pcl_message("PCL found into a build tree.")
  set(PCL_CONF_INCLUDE_DIR "${PCL_DIR}/include") # for pcl_config.h
  set(PCL_LIBRARY_DIRS "${PCL_DIR}/lib/x86_64-linux-gnu")
  set(PCL_SOURCES_TREE "/build/pcl-gWGA5r/pcl-1.10.0+dfsg")
else()
  pcl_report_not_found("PCL can not be found on this machine")
endif()

通过调试,发现环境变量PCL_ROOT设置为/PCL_DIR设置为/lib/x86_64-linux-gnu/cmake/pcl,所以找不到正确的PCL include目录(正确的PCL include目录为/usr/include/pcl-1.10),导致cmake错误。
那么,我的PCL有什么问题,如何通过find_package(PCL REQUIRED)成功找到PCL?非常感谢!

flseospp

flseospp1#

一个简单的“改变位置”的方法是创建一个符号链接。在这种情况下,你可以这样做:

sudo mkdir /lib/x86_64-linux-gnu/cmake/pcl/include
sudo ln -s /usr/include/pcl-1.10/pcl /lib/x86_64-linux-gnu/cmake/pcl/include/pcl

那么你可能会碰到:

No such file or directory
#include <Eigen/Core>

用同样的方法修复它:

sudo ln -s /usr/include/eigen3/Eigen /usr/include/Eigen

相关问题