文章目录

  • 概要
  • 包版本
  • CMakeList.txt


概要

在ROS中使用PCL进行编译时,遇到一些问题,花了一些时间解决了,在此记录下。

包版本

  • ros-noetic
  • PCL-1.10

CMakeList.txt

在ROS中编译使用PCL 1.10的节点时,你需要在你的CMakeLists.txt文件中确保:

  • 找到了PCL 1.10和catkin组件
  • 添加了对C++14的支持
  • 包含了PCL库和头文件
  • 将PCL库链接到你的可执行文件中
cmake_minimum_required(VERSION 3.1)
project(pose_tracker)

## Compile as C++11, supported in ROS Kinetic and newer
#add_compile_options(-std=c++11)
add_compile_options(-std=c++14)
#set(CMAKE_CXX_FLAGS "-std=c++11 -03")
#set(CMAKE_CXX_STANDARD 14)
#set(CMAKE_CXX_STANDARD_REQUIRED ON)
#set(CMAKE_CXX_EXTENSIONS OFF)

#fastdeploy
set(FASTDEPLOY_INSTALL_DIR /root/FastDeploy/build/installed_fastdeploy)
include(${FASTDEPLOY_INSTALL_DIR}/FastDeploy.cmake)
message(STATUS "FASTDEPLOY_LIBS path: " ${FASTDEPLOY_LIBS})

find_package(OpenCV 4.2 EXACT)
message(STATUS "Opencv include path: " ${OpenCV_INCLUDE_DIRS})
message(STATUS "Opencv lib path: " ${OpenCV_LIBRARIES})

find_package(PCL 1.10 REQUIRED)
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})

## Find catkin macros and libraries
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
## is used, also find other catkin packages
find_package(catkin REQUIRED COMPONENTS
  cv_bridge
  eigen_conversions
  geometry_msgs
  image_transport
  message_generation
  roscpp
  sensor_msgs
  nav_msgs
  std_msgs
  pcl_conversions
  pcl_ros 
)

catkin_package(
  INCLUDE_DIRS include
  LIBRARIES pose_tracker
  CATKIN_DEPENDS cv_bridge eigen_conversions geometry_msgs image_transport message_generation roscpp sensor_msgs nav_msgs std_msgs pcl_conversions pcl_ros
  DEPENDS PCL
)

###########
## Build ##
###########

## Specify additional locations of header files
## Your package locations should be listed before other locations
include_directories(
  include
  ${catkin_INCLUDE_DIRS}
  ${FASTDEPLOY_INCS}
  ${OpenCV_INCLUDE_DIRS}
  /usr/include/eigen3
  /usr/include
  /usr/local/include
  ${PCL_INCLUDE_DIRS}
)

file(GLOB SOURCE_FILES src/*.cpp)


add_executable(${PROJECT_NAME}_node ${SOURCE_FILES})

target_include_directories(${PROJECT_NAME}_node PRIVATE
  include
  ${CATKIN_DEVEL_PREFIX}/include/
  ${FASTDEPLOY_INSTALL_DIR}/incldue/
)

## Specify libraries to link a library or executable target against
target_link_libraries(${PROJECT_NAME}_node 
  ${catkin_LIBRARIES}
  ${FASTDEPLOY_LIBS}
  ${OpenCV_LIBRARIES}
  ${FASTDEPLOY_INSTALL_DIR}/lib
  ${PCL_LIBRARIES}
)