简体   繁体   中英

Ubuntu 20.04 can't find PCL because of incorrect include directory after installing it by `sudo apt install libpcl-dev`

OS: Ubuntu20.04
PCL Info:

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

I installed PCL by sudo apt install libpcl-dev . and used it like this:

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)

some errors occured when I build the project:

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!

I'm trying to debug the cmake source code in /lib/x86_64-linux-gnu/cmake/pcl/PCLConfig.cmake:418-454 , The cmake source is shown below:

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()

Through debugging, I found that the environment variable PCL_ROOT is set to / and PCL_DIR is set to /lib/x86_64-linux-gnu/cmake/pcl . So, It can't find correct PCL include directory(the correct PCL include dir is /usr/include/pcl-1.10 ) and lead to cmake error.

So, what's the problem with my PCL, and how can I find PCL by find_package(PCL REQUIRED) successfully? Thanks a lot!

An easy way to "change the location" of something is to create a symlink. In this case, you'd do:

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

Then you'll probably hit:

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

Fix it in the same way:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM