Collin B
Collin B

Reputation: 51

Segmentation fault before main with pcl::ExtractIndices (pcl, ROS, catkin)

I am attempting to run the following in C++:

#include <pcl_ros/point_cloud.h>
#include "pcl/pcl_base.h"
#include "pcl/PointIndices.h"
#include "pcl/conversions.h"
#include <pcl/kdtree/kdtree_flann.h>
#include <pcl/filters/extract_indices.h>
#include <pcl/filters/voxel_grid.h>

using namespace std;
using namespace pcl;

void myFunction() {
     ...
     ExtractIndices<PointXYZ> rangefilter;
     ...
}

int main() {
     cout << "Hello" << endl;
}

The code compiles, but I get a segmentation fault as soon as I run it; the cout statement isn't executed. Notice I don't actually even call myFunction() in main. The only error message is

Segmentation fault (core dumped)

When I comment out the ExtractIndices line in myFunction, the problem goes away and the code runs fine:

     // ExtractIndices<PointXYZ> rangefilter;

I am running this on Ubuntu with ROS and compiling it with catkin_make, if that helps.

I'd really appreciate some help debugging this, as I've been stuck on this problem for a while. Thanks for reading!

Upvotes: 2

Views: 1606

Answers (1)

Collin B
Collin B

Reputation: 51

Thanks to the help from the commenters, I was able to find the issue. I did a backtrace with gdb and googled the output:

boost::math::lanczos::lanczos_initializer<boost::math::lanczos::lanczos17m64, long double>::init::init()

Then found this: http://answers.ros.org/question/194699/segmentation-fault-when-using-correspondencerejectorsampleconsensus/

Which says that you can't use C++11 with PCL, so I removed this line from my CMakeLists.txt file:

set(CMAKE_CXX_FLAGS "-std=c++0x ${CMAKE_CXX_FLAGS}")

And it worked!

Upvotes: 1

Related Questions