ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

How does on include the PCL library to an existing ros package code?

asked 2019-10-04 04:46:10 -0600

Inshal240 gravatar image

updated 2019-10-18 07:57:11 -0600

I am trying to convert my code from using a vector of particles to a proper point cloud implementation. I want to use the octree module of PCL for radius based searches. However, when compiling the code, I get undefined references to Octree library functions.

I am using Ubuntu 18.04.3 LTS with ROS-melodic. I tried including PCL-1.8 under /usr/include in my CMakeLists.txt file as well as downloading and adding PCL-1.9.1 under my ros package (which crashes my PC during compilation). I am also not able to find_package() the pcl library.

Any help would be greatly appreciated.

cmake_minimum_required(VERSION 2.8.3)
project(points_reader)

add_compile_options(-std=c++17)

set(${PROJECT_NAME}_DEPS
  dynamic_reconfigure
  message_runtime
  roscpp
  rospy
  toposens_pointcloud
  toposens_driver
  toposens_msgs
  tf
  # pcl
  pcl_conversions
  pcl_ros
  sensor_msgs
)

find_package(
  catkin REQUIRED
  COMPONENTS ${${PROJECT_NAME}_DEPS}
)

############
## Config ##
############

catkin_package(
  INCLUDE_DIRS include
  LIBRARIES ${PROJECT_NAME}
  CATKIN_DEPENDS ${${PROJECT_NAME}_DEPS}
)

################
## Executable ##
################

add_subdirectory(external/pcl)

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

include_directories(
  include 
  external
  ${catkin_INCLUDE_DIRS}
)

add_library(
  ${PROJECT_NAME}
  src/line.cpp
  src/fitness_evaluator.cpp
  src/points_reader.cpp
  src/points_mapper.cpp
  src/bounding_box.cpp
  src/points_publisher.cpp
)

add_dependencies(
  ${PROJECT_NAME}
  # ${PROJECT_NAME}_gencfg
  ${catkin_EXPORTED_TARGETS}
)

add_executable(
  ${PROJECT_NAME}_node
  src/points_reader_node.cpp
)

target_link_libraries(
  ${PROJECT_NAME}_node
  ${PROJECT_NAME}
  ${catkin_LIBRARIES}
  ${PCL_LIBRARIES}
)

install(
  TARGETS ${PROJECT_NAME}_node
  RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
  COMPONENT main
)

##########
## Test ##
##########

if(CATKIN_ENABLE_TESTING)
  add_subdirectory(tests)
endif()
edit retag flag offensive close merge delete

Comments

2

You should not need the link_directories(..). I would also suggest to remove everything related to your "external PCL" from your CMakeLists.txt.

If PCL 1.8 is sufficient (in Melodic), depending on pcl_ros should import all required dependencies (including PCL itself).

gvdhoorn gravatar image gvdhoorn  ( 2019-10-04 06:34:13 -0600 )edit
1

And I'm a bit confused, you stated, you are using Ubuntu 16.04 with ROS melodic, I shouldn't it either be kinetic or Ubuntu 18.04?

LeoE gravatar image LeoE  ( 2019-10-04 06:47:33 -0600 )edit

I will double-check on the Ubuntu version. I believe you may be right about it being 18.04

EDIT: It was. I updated the question.

Inshal240 gravatar image Inshal240  ( 2019-10-04 12:19:44 -0600 )edit

2 Answers

Sort by ยป oldest newest most voted
0

answered 2019-10-04 12:24:25 -0600

Inshal240 gravatar image

I found out the cause of the issue. I was getting the undefined reference issue because the PointT template argument I was using for OctreePointCloudSearch was included after the octree's header file. So it tried to instantiate the template using a class that didn't exist. Hence the reference errors.

I removed all the external pcl references from my header file and stuck to what the tutorial showed and it still compiles.

Thank you everyone for your help and time!

edit flag offensive delete link more
0

answered 2019-10-04 05:24:42 -0600

LeoE gravatar image

You need to find_package PCL: find_package(PCL 1.9.1 REQUIRED COMPONENTS common io)

edit flag offensive delete link more

Comments

1

Depending on pcl_ros should be sufficient.

@Inshal240: could you please show us the linker error itself?

gvdhoorn gravatar image gvdhoorn  ( 2019-10-04 06:33:00 -0600 )edit

I will upload the linker messages for future searches :)

Inshal240 gravatar image Inshal240  ( 2019-10-04 12:23:04 -0600 )edit

@LeoE Apparently one does not need to find_package() pcl because otherwise, it throws errors of there being two pcl environments. One under /usr/include and another under /usr/local/lib or something similar...

Inshal240 gravatar image Inshal240  ( 2019-10-04 12:29:46 -0600 )edit

@Inshal240: those errors are most likely caused by your own experiments with PCL 1.9 and 1.8.

gvdhoorn gravatar image gvdhoorn  ( 2019-10-04 12:43:06 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2019-10-04 04:46:10 -0600

Seen: 2,946 times

Last updated: Oct 18 '19