cmake - find_package(PCL 1.2 REQUIRED) 使用 CMake 返回错误路径

标签 cmake point-cloud-library

我使用的是 Ubuntu 12.04 机器,但遇到以下问题:
我正在尝试使用 CMake 编译和构建 C++ 文件,但是当我在“cmake ..”之后给出命令“make”时,出现错误:

pcl_openni_grabber.cpp:2:29: fatal error: pcl/point_cloud.h: No such file or directory compilation terminated.



现在我的 CMakeLists.txt 如下:
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)

project(pcl-openni-grabber)

find_package(PCL 1.2 REQUIRED)

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

add_executable (pcl_openni_grabber pcl_openni_grabber.cpp)
target_link_libraries (pcl_openni_grabber ${PCL_LIBRARIES})

其中环境变量 PCL_INCLUDE_DIRS 包含:
/usr/include/pcl-1.5

现在经过 2 个小时的工作来理解问题,我在命令 find_package() 中找到了它。实际上,当我运行“cmake ..”时,它返回到 pcl(点云库)库的错误路径。实际上这是“cmake ..”的输出:
-- The C compiler identification is GNU
-- The CXX compiler identification is GNU
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- checking for module 'eigen3'
--   found eigen3, version 3.0.5
-- Found eigen: /usr/include/eigen3 
-- Boost version: 1.46.1
-- Found the following Boost libraries:
--   system
--   filesystem
--   thread
--   date_time
--   iostreams
-- checking for module 'flann'
--   found flann, version 1.7.1
-- Found Flann: /opt/ros/fuerte/lib/libflann_cpp_s.a 
-- checking for module 'openni-dev'
--   found openni-dev, version 1.5.2.23~precise
-- Found openni: /usr/lib/libOpenNI.so 
-- Found libusb-1.0: /usr/include 
-- Found qhull: /usr/lib/libqhull.so 
-- looking for PCL_COMMON
-- Found PCL_COMMON: /opt/ros/fuerte/lib/libpcl_common.so 
-- looking for PCL_KDTREE
-- Found PCL_KDTREE: /opt/ros/fuerte/lib/libpcl_kdtree.so 
-- looking for PCL_OCTREE
-- Found PCL_OCTREE: /opt/ros/fuerte/lib/libpcl_octree.so 
-- looking for PCL_SEARCH
-- Found PCL_SEARCH: /opt/ros/fuerte/lib/libpcl_search.so 
-- looking for PCL_SAMPLE_CONSENSUS
-- Found PCL_SAMPLE_CONSENSUS: /opt/ros/fuerte/lib/libpcl_sample_consensus.so 
-- looking for PCL_FILTERS
-- Found PCL_FILTERS: /opt/ros/fuerte/lib/libpcl_filters.so 
-- looking for PCL_TRACKING
-- Found PCL_TRACKING: /opt/ros/fuerte/lib/libpcl_tracking.so 
-- looking for PCL_IO
-- Found PCL_IO: /opt/ros/fuerte/lib/libpcl_io.so 
-- looking for PCL_FEATURES
-- Found PCL_FEATURES: /opt/ros/fuerte/lib/libpcl_features.so 
-- looking for PCL_REGISTRATION
-- Found PCL_REGISTRATION: /opt/ros/fuerte/lib/libpcl_registration.so 
-- looking for PCL_SEGMENTATION
-- Found PCL_SEGMENTATION: /opt/ros/fuerte/lib/libpcl_segmentation.so 
-- looking for PCL_SURFACE
-- Found PCL_SURFACE: /opt/ros/fuerte/lib/libpcl_surface.so 
-- looking for PCL_VISUALIZATION
-- Found PCL_VISUALIZATION: /opt/ros/fuerte/lib/libpcl_visualization.so 
-- looking for PCL_KEYPOINTS
-- Found PCL_KEYPOINTS: /opt/ros/fuerte/lib/libpcl_keypoints.so 
-- Found PCL: /usr/lib/libboost_system-mt.so;/usr/lib/libboost_filesystem-mt.so;/usr/lib/libboost_thread-mt.so;pthread;/usr/lib/libboost_date_time-mt.so;/usr/lib/libboost_iostreams-mt.so;optimized;/opt/ros/fuerte/lib/libpcl_common.so;debug;/opt/ros/fuerte/lib/libpcl_common.so;optimized;/opt/ros/fuerte/lib/libflann_cpp_s.a;debug;/opt/ros/fuerte/lib/libflann_cpp_s-gd.a;optimized;/opt/ros/fuerte/lib/libpcl_kdtree.so;debug;/opt/ros/fuerte/lib/libpcl_kdtree.so;optimized;/opt/ros/fuerte/lib/libpcl_octree.so;debug;/opt/ros/fuerte/lib/libpcl_octree.so;optimized;/opt/ros/fuerte/lib/libpcl_search.so;debug;/opt/ros/fuerte/lib/libpcl_search.so;optimized;/opt/ros/fuerte/lib/libpcl_sample_consensus.so;debug;/opt/ros/fuerte/lib/libpcl_sample_consensus.so;optimized;/opt/ros/fuerte/lib/libpcl_filters.so;debug;/opt/ros/fuerte/lib/libpcl_filters.so;optimized;/opt/ros/fuerte/lib/libpcl_tracking.so;debug;/opt/ros/fuerte/lib/libpcl_tracking.so;/usr/lib/libOpenNI.so;vtkCommon;vtkRendering;vtkHybrid;optimized;/opt/ros/fuerte/lib/libpcl_io.so;debug;/opt/ros/fuerte/lib/libpcl_io.so;optimized;/opt/ros/fuerte/lib/libpcl_features.so;debug;/opt/ros/fuerte/lib/libpcl_features.so;optimized;/opt/ros/fuerte/lib/libpcl_registration.so;debug;/opt/ros/fuerte/lib/libpcl_registration.so;optimized;/opt/ros/fuerte/lib/libpcl_segmentation.so;debug;/opt/ros/fuerte/lib/libpcl_segmentation.so;optimized;/usr/lib/libqhull.so;debug;/usr/lib/libqhull.so;optimized;/opt/ros/fuerte/lib/libpcl_surface.so;debug;/opt/ros/fuerte/lib/libpcl_surface.so;optimized;/opt/ros/fuerte/lib/libpcl_visualization.so;debug;/opt/ros/fuerte/lib/libpcl_visualization.so;optimized;/opt/ros/fuerte/lib/libpcl_keypoints.so;debug;/opt/ros/fuerte/lib/libpcl_keypoints.so (Required is at least version "1.2")
-- Configuring done
-- Generating done
-- Build files have been written to: /home/jacopo/dev/university/prova/build

如您所见,它返回特定 ros(机器人操作系统)包的 pcl 库的路径,该包通过 Synaptic 包管理器安装在“/opt/ros”目录中。正确的 pcl 库和包含在“/usr/include/pcl.1.5”和“/usr/lib”中。

卸载 ros 时,find_package 返回正确的路径,我可以毫无问题地编译和构建。但是由于我需要 ros 上大学,同时我需要 cmake,我如何在安装了 ros 的情况下让 cmake 工作?任何的想法?

最佳答案

您可以在 find_package 中微调搜索路径命令:

find_package(PCL 1.2 REQUIRED PATHS /usr NO_DEFAULT_PATH)

这可能有点暴力;您也许可以找到更好的方法来排除 /opt从 CMake 搜索包时考虑。

顺便说一句,您可能不应该使用 link_directories .文档说明了为什么通常不需要它。

关于cmake - find_package(PCL 1.2 REQUIRED) 使用 CMake 返回错误路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10572287/

相关文章:

list - 如何将 CMake 列表作为集合进行操作?

c++ - 最佳 PCL 模板对齐设置

c++ - 点云的描述符

c++ - 在我的项目中添加 sqlite3 库时出现错误消息

c++ - 使用 MSVC 2013 和 2015,使用 CMake 和 ExternalProject_Add 通过引用将 std::vector 传递给导出的成员函数

c++ - 使用 PCL 的 BreadthFirstIterator 时出现 LNK2001 错误

c++ - 在 rgb 图像中使用来自点云的聚簇索引

c++ - 在 pcl 查看器中绘制样条曲线

windows - 从 CMake/PkgConfig 为 pkg-config 提供选项 --define-variable

c++ - 在 Mac OS X Mojave 上使用 AppleClang 编译和链接 OpenMP