[build error]Converting pcl::PCLPointCloud2 to sensor_msg::PointCloud2
While extracting point cloud from stl model data to publish it using ROS topic, I need to convert pcl::PCLPointCloud2
to sensor_msg::PointCloud2
.
So I did like below::
#include <pcl/io/vtk_lib_io.h>
#include <pcl/PolygonMesh.h>
#include <pcl/PCLPointCloud2.h>
#include <pcl_conversions/pcl_conversions.h>
#include "sensor_msgs/PointCloud2.h"
int main(int argc, char* argv[])
{
const std::string meshFileName = "test.stl";
pcl::PolygonMesh testMesh;
pcl::io::loadPolygonFile(meshFileName, testMesh);
pcl::PCLPointCloud2 pc2;
sensor_msgs::PointCloud2 p_msg;
pcl_conversions::fromPCL(pc2, p_msg);
}
But I got error below. How can I fix it? Or is there another way to convert PCLPointCloud2 to ROSMsg?
Scanning dependencies of target stl2pcd
[ 50%] Built target pcd_read
[100%] Building CXX object try_pkg/CMakeFiles/stl2pcd.dir/src/stl2pcd.cpp.o
Linking CXX executable /home/wkentaro/semi/devel/lib/try_pkg/stl2pcd
CMakeFiles/stl2pcd.dir/src/stl2pcd.cpp.o: In function pcl_conversions::fromPCL(unsigned long const&, ros::Time&)':
stl2pcd.cpp:(.text._ZN15pcl_conversions7fromPCLERKmRN3ros4TimeE[_ZN15pcl_conversions7fromPCLERKmRN3ros4TimeE]+0x7e): undefined reference to
ros::TimeBase<ros::time, ros::duration="">::fromNSec(unsigned long)'
collect2: error: ld returned 1 exit status
make[2]: * [/home/wkentaro/semi/devel/lib/try_pkg/stl2pcd] Error 1
make[1]: [try_pkg/CMakeFiles/stl2pcd.dir/all] Error 2
make: ** [all] Error 2
Invoking "make -j4 -l4" failed