I'm trying to use the VoxelGrid of the pcl library to filter my PointCloud, extracted from a ros message. So the following is the part of code related to this problem:
pcl::PCLBase<pcl::PCLPointCloud2>::PCLPointCloud2ConstPtr cloudPtr(cloud_pc2);
pcl::VoxelGrid<pcl::PCLPointCloud2> sor;
sor.setInputCloud(cloudPtr);
sor.setLeafSize(0.1f, 0.1f, 0.1f);
sor.filter(cloud_filtered);
I saw online tutorials where they directly do:
pcl::PCLPointCloud2::Ptr cloud_filtered (new pcl::PCLPointCloud2 ());
pcl::VoxelGrid<pcl::PCLPointCloud2> sor;
sor.setInputCloud (cloud);
sor.setLeafSize (0.01f, 0.01f, 0.01f);
sor.filter (*cloud_filtered);
But in both cases I got undefined reference for the setInputCloud function. Have someone an idea of why this happens? I will attach also my CmakeList file
cmake_minimum_required(VERSION 3.5)
project(loam_os2)
# 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)
set(CMAKE_CXX_STANDARD 17)
endif()
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()
# find dependencies
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(std_msgs REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(PCL 1.10 REQUIRED)
find_package(pcl_conversions REQUIRED)
find_package(tf2_ros REQUIRED)
find_package(tf2 REQUIRED)
include_directories(${PCL_INCLUDE_DIRS} include)
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
add_executable(pcl_example_node src/pcl_example.cpp src/pcl_example_node.cpp)
target_link_libraries( pcl_example_node
${PCL_LIBRARIES}
)
ament_target_dependencies(
pcl_example_node
rclcpp
std_msgs
sensor_msgs
pcl_conversions
tf2
tf2_ros
)
install(TARGETS
pcl_example_node
DESTINATION lib/${PROJECT_NAME})
# Install launch files.
install(DIRECTORY
launch
DESTINATION share/${PROJECT_NAME}/
)
if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
# the following line skips the linter which checks for copyrights
# uncomment the line when a copyright and license is not present in all source files
#set(ament_cmake_copyright_FOUND TRUE)
# the following line skips cpplint (only works in a git repo)
# uncomment the line when this package is not in a git repo
#set(ament_cmake_cpplint_FOUND TRUE)
ament_lint_auto_find_test_dependencies()
endif()
ament_package()
Thank you in advance for any suggestion
here the full error:
usr/bin/ld: CMakeFiles/pcl_example_node.dir/src/pcl_example.cpp.o: in function Pcl_example::lidar_callback(std::shared_ptr<sensor_msgs::msg::PointCloud2_<std::allocator<void> > >)':
pcl_example.cpp:(.text+0x122f): undefined reference topcl::PCLBase<pcl::PCLPointCloud2>::setInputCloud(std::shared_ptr<pcl::PCLPointCloud2 const> const&)'
collect2: error: ld returned 1 exit status
make[2]: * [CMakeFiles/pcl_example_node.dir/build.make:360: pcl_example_node] Error 1
make[1]: * [CMakeFiles/Makefile2:78: CMakeFiles/pcl_example_node.dir/all] Error 2
make: *** [Makefile:141: all] Error 2
Failed <<< loam_os2 [12.2s, exited with code 2]
Summary: 0 packages finished [12.5s]
1 package failed: loam_os2
1 package had stderr output: loam_os2
Starting with version 1.11.0, PCL uses
std::shared_ptr
instead ofboost::shared_ptr
. It seems you are using PCL 1.10, sosetInputCloud
would expect aboost::shared_ptr
, however you are passing astd::shared_ptr
. Since I can't see wherecloudPtr
orcloud
respectively come from in your code snippets, I am unable to suggest a solution, except to use a newer PCL version.