Reputation: 3002
The following code:
#include <ros/ros.h>
#include <pcl_ros/point_cloud.h>
#include <pcl/point_types.h>
#include <boost/foreach.hpp>
typedef pcl::PointCloud<pcl::PointXYZ> PointCloud;
void callback(const PointCloud::ConstPtr& msg)
{
printf ("Cloud: width = %d, height = %d\n", msg->width, msg->height);
BOOST_FOREACH (const pcl::PointXYZ& pt, msg->points)
printf ("\t(%f, %f, %f)\n", pt.x, pt.y, pt.z);
}
int main(int argc, char** argv)
{
ros::init(argc, argv, "sub_pcl");
ros::NodeHandle nh;
ros::Subscriber sub = nh.subscribe<PointCloud>("points2", 1, callback);
ros::spin();
}
Which is a default example taken from here
My CMake:
cmake_minimum_required(VERSION 2.6 FATAL_ERROR)
find_package(PCL 1.3 REQUIRED COMPONENTS common io)
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
target_link_libraries(${PROJECT_NAME} ${PCL_COMMON_LIBRARIES} ${PCL_IO_LIBRARIES})
Which is the exact configuration recommended on the pcl official website
I still get the following linking error:
CMakeFiles/apsp_manifold.dir/src/apsp_manifold.cpp.o: In function `void pcl::detail::FieldMapper<pcl::PointXYZ>::operator()<pcl::fields::z>()':
/usr/include/pcl-1.7/pcl/conversions.h:106: undefined reference to `pcl::console::print(pcl::console::VERBOSITY_LEVEL, char const*, ...)'
CMakeFiles/apsp_manifold.dir/src/apsp_manifold.cpp.o: In function `void pcl::detail::FieldMapper<pcl::PointXYZ>::operator()<pcl::fields::y>()':
/usr/include/pcl-1.7/pcl/conversions.h:106: undefined reference to `pcl::console::print(pcl::console::VERBOSITY_LEVEL, char const*, ...)'
CMakeFiles/apsp_manifold.dir/src/apsp_manifold.cpp.o: In function `void pcl::detail::FieldMapper<pcl::PointXYZ>::operator()<pcl::fields::x>()':
/usr/include/pcl-1.7/pcl/conversions.h:106: undefined reference to `pcl::console::print(pcl::console::VERBOSITY_LEVEL, char const*, ...)'
What do I have the above described error and how can I remove it?
Upvotes: 2
Views: 3891
Reputation: 3002
The problem was as follow: the code from the tutorial was old, the last time the page was modified - 2011-08-09.
The only reasonable explanation I could find is that apparently the PCL library did not remove from the headers the code related to older versions, but removed only the symbol files related to those function calls, so what would happen is: the parsing would succeed (as the function declarations are there) while the linking would fail since there is nothing to link. This is the tutorial I ended up using.
Upvotes: 0
Reputation: 5027
Just a guess, but maybe the problem is that not all required components are included.
This is how I link PCL:
find_package(PCL REQUIRED)
include_directories( ... ${PCL_INCLUDE_DIRS})
...
target_link_libraries( ... ${PCL_LIBRARIES})
Upvotes: 1