2017-09-15 24 views
-2

我正在使用PCL开发ROS包。在C++中运行后的模板化类错误11

问题在于它使用C++ 98和C++ 11编译成功。但是,当节点在支持C++ 11的版本(CMakeLists L:5,未注释)中启动时,它立即发生段错误,尽管在没有使用C++ 11的情况下编译时它工作正常。

this包的相同代码体系结构(模板化库)显示相同的行为。

我发现模板库是保持原因的人。 但是,我还没弄明白。我在这里错过了什么?

平台:Ubuntu 14.04,ROS Indigo,GCC 4.8.4。

谢谢。

节点代码:

#include <ros/ros.h> 
#include "pcl_tools.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> 
#include <pcl/filters/voxel_grid.h> 
using namespace pcl_tools; 
ros::Publisher pub; 

void cloud_cb (const sensor_msgs::PointCloud2ConstPtr& input) 
{ 
    /// ros to pcl cloud 
    pcl::PCLPointCloud2 cloud2_in; 
    pcl_conversions::toPCL(*input,cloud2_in); 
    pcl::PointCloud< pcl::PointXYZ>::Ptr temp_cloud(new pcl::PointCloud< pcl::PointXYZ>); 
    pcl::fromPCLPointCloud2(cloud2_in,*temp_cloud); 

    /// use templated function 
    pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_filtered (new pcl::PointCloud<pcl::PointXYZ>); 
    cloud_filtered = passthroughfilter<pcl::PointXYZ>(temp_cloud, "y", -2, 2.0); 
} 

int main (int argc, char** argv) 
{ 
    ros::init (argc, argv, "template_test"); 
    ros::NodeHandle nh; 
    ros::Subscriber sub = nh.subscribe ("/camera/depth/points", 1, cloud_cb); 
    ros::spin(); 
} 

模板头:

#ifndef PCL_TOOLS 
#define PCL_TOOLS 

#include <pcl/point_cloud.h> 
#include <pcl/point_types.h> 
#include <pcl/filters/passthrough.h> 
#include <string> 
#include <sstream> 
#include <assert.h> 

namespace pcl_tools 
{ 
    template <typename pointT> boost::shared_ptr< pcl::PointCloud<pointT> > 
    passthroughfilter(boost::shared_ptr< pcl::PointCloud<pointT> >, std::string, float, float, bool invert = false); 
} 

template <typename pointT> 
boost::shared_ptr< pcl::PointCloud<pointT> > pcl_tools::passthroughfilter(boost::shared_ptr< pcl::PointCloud<pointT> > input, 
                   std::string axis, float min , float max, bool invert = false) 
{ 
    typedef boost::shared_ptr< pcl::PointCloud<pointT> > PointCloudPtr; 
    PointCloudPtr cloud(new pcl::PointCloud<pointT>); 

    // Create the filtering object 
    pcl::PassThrough<pointT> pass; 
    pass.setInputCloud (input); 
    pass.setFilterFieldName (axis); 
    pass.setFilterLimits (min, max); 
    pass.setFilterLimitsNegative (invert); 
    pass.filter (*cloud); 
    return cloud; 
} 
#endif 

的CMakeLists.txt

cmake_minimum_required(VERSION 2.8.3) 
project(test_template) 

## Compile as C++11, supported in ROS Kinetic and newer 
add_compile_options(-std=c++11) 

find_package(catkin REQUIRED COMPONENTS 
    cv_bridge 
    geometry_msgs 
    image_transport 
    pcl_conversions 
    pcl_ros 
    roscpp 
    rospy 
    sensor_msgs 
    std_msgs 
) 

add_definitions(${PCL_DEFINITIONS}) 
catkin_package() 

include_directories(
    include/${PROJECT_NAME} 
    ${catkin_INCLUDE_DIRS} 
    ${PCL_INCLUDE_DIRS} 
) 

link_directories(${PCL_LIBRARY_DIRS}) 

add_executable(pcl_template_test src/pcl_template.cpp) 
target_link_libraries(pcl_template_test ${catkin_LIBRARIES}) 
+4

你有没有使用过调试器? – Klaus

+0

嗯,是的。但我遇到了同样的问题,使用这个[包](https://github.com/spencer-project/spencer_people_tracking/tree/master/detection/rgbd_detectors/pcl_people_detector),sio,我怀疑更多的作为模板规格差异的C++ 11版本。此外,你有没有使用ROS,因为调试不是那么相关... – Vtik

回答

0

嗯,事实证明这是由PCL图书馆抛出的。实际上,通过apt-get安装PCL将安装非C++ 11兼容版本。所以,为了克服这个问题,我必须从源代码重新编译它,并添加C++ 11支持。更多关于这个问题here