2

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!

Collin B
  • 51
  • 6
  • 1
    where does the debugger say it goes bang? – pm100 Apr 08 '15 at 22:17
  • The reason for crashes before `main` is mostly due to global or static objects being constructed before main() has run, and the construction of these objects causes the error. You need to get a stack trace of the functions called that led up to the crash. – PaulMcKenzie Apr 08 '15 at 22:26
  • [Start here](https://sourceware.org/gdb/onlinedocs/gdb/). – n. m. could be an AI Apr 08 '15 at 22:52

1 Answers1

1

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!

Collin B
  • 51
  • 6