Compiling with Cmake and PCL

asked 2018-03-10 04:50:50 -0500

ARB gravatar image

updated 2022-01-22 16:16:25 -0500

Evgeny gravatar image

Hi, I am trying to execute the sample programs available in pcl tutorials. I am getting following error while building with catkin_make. Cmakelists and sample code is attaxhed below.

CMake lists:

cmake_minimum_required(VERSION 2.8.3)
project(pcl_ros_tutorial)

find_package(catkin REQUIRED COMPONENTS
  pcl_conversions
  pcl_ros
  roscpp
  sensor_msgs
)

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

add_executable(example src/example.cpp)
target_link_libraries(example ${catkin_LIBRARIES} ${PCL_COMMON_LIBRARIES} ${PCL_IO_LIBRARIES})

include_directories(
# include
  ${catkin_INCLUDE_DIRS}
)

example.cpp

    #include <ros/ros.h>
    // PCL specific includes
    #include <sensor_msgs/PointCloud2.h>
    #include <pcl_conversions/pcl_conversions.h>
    #include <pcl/point_cloud.h>
    #include <pcl/point_types.h>

    ros::Publisher pub;

   void 
   cloud_cb (const sensor_msgs::PointCloud2ConstPtr& input)
   {
     // Create a container for the data.
     sensor_msgs::PointCloud2 output;

     output = *input;

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

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

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

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

     // Spin
     ros::spin ();
   }

Error:

CMake Error at pcl_ros_tutorial/CMakeLists.txt:34 (target_link_libraries):
  Attempt to add link library
  "/usr/lib/x86_64-linux-gnu/libboost_serialization.so" to target "example"
  which is not built in this directory.
edit retag flag offensive close merge delete

Comments

On my system, your CMakeLists.txt and example.cpp build fine as you posted them (Ubuntu 16.04 LTS, ROS Kinetic Kame, all dependencies from the Ubuntu and/or ROS repositories and tested in a new package "pcl_ros_tutorial" in my usual workspace).

Maarten gravatar image Maarten  ( 2018-03-10 09:58:15 -0500 )edit

@Maarten Did you install pcl seperately in Ubuntu..other than ros dependencies?

ARB gravatar image ARB  ( 2018-03-10 10:07:20 -0500 )edit

I installed the ros-kinetic-pcl-ros package, which depends on libpcl-dev and other libpcl packages. I think you have a problem with your workspace and/or package configuration. Does it work in a new workspace and package?

Maarten gravatar image Maarten  ( 2018-03-10 10:27:00 -0500 )edit