PCL catkin_make error : undefined reference to `pcl::Filter<pcl::PCLPointCloud2>

asked 2020-01-30 11:45:07 -0500

Nikkolas Edi gravatar image

This is the .cpp code:

#include <ros/ros.h>
#include <pcl_ros/point_cloud.h>
#include <pcl/point_types.h>
#include <boost/foreach.hpp>
#include <pcl/filters/crop_box.h>
#include <sensor_msgs/PointCloud2.h>
#include <sensor_msgs/point_cloud2_iterator.h>

 ros::Publisher pub;

 void cloud_cb (const sensor_msgs::PointCloud2ConstPtr& cloud_msg)
 {

 pcl::PCLPointCloud2* cloud = new pcl::PCLPointCloud2;
 pcl::PCLPointCloud2ConstPtr cloudPtr(cloud);
 pcl::PCLPointCloud2 cloud_filtered;

 // Do data processing here...
 pcl_conversions::toPCL(*cloud_msg, *cloud);

 pcl::CropBox<pcl::PCLPointCloud2> boxFilter;
 boxFilter.setInputCloud(cloudPtr);
 boxFilter.setMin(Eigen::Vector4f(1.0, 1.0, 1.0, 0));
 boxFilter.setMax(Eigen::Vector4f(4.0, 4.0, 4.0, 0));
 boxFilter.setTranslation(Eigen::Vector3f(0.0, 0.0, 0.0));
 boxFilter.filter(cloud_filtered);

 sensor_msgs::PointCloud2 output;
 pcl_conversions::fromPCL(cloud_filtered, output);

 for (sensor_msgs::PointCloud2ConstIterator<float> it(output, "x"); it != it.end(); ++it) {
     // TODO: do something with the values of x, y, z

     std::cout <<  it[0] << "/ ";
     std::cout <<  it[1]<< "/ ";
     std::cout <<  it[2]<< "/ ";
     std::cout << std::endl;
 }

 // Publish the data.
 pub.publish (output);

 }

 int main (int argc, char** argv)
{
// Initialize ROS
ros::init (argc, argv, "CROP");
ros::NodeHandle nh;

// Create a ROS subscriber for the input point cloud
ros::Subscriber sub = nh.subscribe ("/camera/depth/points", 1, cloud_cb);

// Create a ROS publisher for the output point cloud
pub = nh.advertise<sensor_msgs::PointCloud2> ("/Cloud_Cropped", 1);

// Spin
ros::spin ();
}

This is my CMakeLists.txt:

cmake_minimum_required(VERSION 2.8)
project(pcl_ros)

## Find system dependencies
find_package(cmake_modules REQUIRED)
find_package(Boost REQUIRED COMPONENTS system filesystem thread)
find_package(Eigen3 REQUIRED)
find_package(PCL REQUIRED)

if(NOT "${PCL_LIBRARIES}" STREQUAL "")
  # For debian: https://github.com/ros-perception/perception_pcl/issues/139
  list(REMOVE_ITEM PCL_LIBRARIES
    "vtkGUISupportQt"
    "vtkGUISupportQtOpenGL"
    "vtkGUISupportQtSQL"
    "vtkGUISupportQtWebkit"
    "vtkViewsQt"
    "vtkRenderingQt")
endif()

# Remove include dirs which does not exist in some platforms.
# https://github.com/ros-perception/perception_pcl/issues/172
# https://github.com/ros-perception/perception_pcl/issues/206
if(NOT "${PCL_INCLUDE_DIRS}" STREQUAL "")
  foreach(item ${PCL_INCLUDE_DIRS})
    set(patterns "/usr/include/.*-linux-gnu/freetype2" "/usr/include/hdf5/openmpi")
    foreach(pattern ${patterns})
      string(REGEX MATCH ${pattern} match ${item})
      if(match)
        list(REMOVE_ITEM PCL_INCLUDE_DIRS ${match})
      endif()
    endforeach()
  endforeach()
endif()

## Find catkin packages
find_package(catkin REQUIRED COMPONENTS
  dynamic_reconfigure
  genmsg
  nodelet
  nodelet_topic_tools
  pcl_conversions
  pcl_msgs
  pluginlib
  rosbag
  rosconsole
  roscpp
  roslib
  sensor_msgs
  std_msgs
  tf
  tf2_eigen
)

## Add include directories
include_directories(include
  ${Boost_INCLUDE_DIRS}
  ${catkin_INCLUDE_DIRS}
  ${EIGEN3_INCLUDE_DIRS}
  ${PCL_INCLUDE_DIRS}
)

## Generate dynamic_reconfigure
generate_dynamic_reconfigure_options(
  cfg/EuclideanClusterExtraction.cfg
  cfg/ExtractIndices.cfg
  cfg/ExtractPolygonalPrismData.cfg
  cfg/Feature.cfg
  cfg/Filter.cfg
  cfg/MLS.cfg
  cfg/SACSegmentation.cfg
  cfg/SACSegmentationFromNormals.cfg
  cfg/SegmentDifferences.cfg
  cfg/StatisticalOutlierRemoval.cfg
  cfg/RadiusOutlierRemoval.cfg
  cfg/VoxelGrid.cfg
  cfg/CropBox.cfg
)

## Declare the catkin package
catkin_package(
  INCLUDE_DIRS include
  LIBRARIES
    pcl_ros_filters
    pcl_ros_io
    pcl_ros_tf
  CATKIN_DEPENDS
    dynamic_reconfigure
    message_filters
    nodelet
    nodelet_topic_tools
    pcl_conversions
    pcl_msgs
    rosbag
    roscpp
    sensor_msgs
    std_msgs
    tf
  DEPENDS
    Boost
    EIGEN3
    PCL
)

## Declare the pcl_ros_tf library
add_library(pcl_ros_tf src/transforms.cpp)
target_link_libraries(pcl_ros_tf ${Boost_LIBRARIES} ${catkin_LIBRARIES} ${EIGEN3_LIBRARIES} ${PCL_LIBRARIES})
add_dependencies(pcl_ros_tf ${catkin_EXPORTED_TARGETS})

## Nodelets

## Declare the pcl_ros_io library
add_library(pcl_ros_io
  src/pcl_ros/io/bag_io.cpp
  src/pcl_ros/io/concatenate_data.cpp
  src/pcl_ros/io/concatenate_fields.cpp
  src/pcl_ros/io/io.cpp
  src/pcl_ros/io/pcd_io.cpp
)
target_link_libraries(pcl_ros_io pcl_ros_tf ${Boost_LIBRARIES} ${catkin_LIBRARIES} ${EIGEN3_LIBRARIES} ${PCL_LIBRARIES})
class_loader_hide_library_symbols(pcl_ros_io)

## Declare the pcl_ros_features library
add_library(pcl_ros_features
  src/pcl_ros/features/feature.cpp
  # Compilation is ...
(more)
edit retag flag offensive close merge delete