Segmentation fault (core dumped) : PCL tutorial
Hey, I am new to ROS (Version Jade-1.11.20) and want to work with pointclouds. I followed the first ROS PCL tutorial as written in http://wiki.ros.org/pcl/Tutorials . However, rosrun
leads to the following error output:
rosrun my_pcl_tutorial example input:=/narrow_stereo_textured/points2
Segmentation fault (core dumped)
Normally, that would mean that pointers are screwed up, but as I simply copy-pasted the code from the tutorial, the following example.cpp
file should be correct:
#include <ros/ros.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>
ros::Publisher pub;
void
cloud_cb (const sensor_msgs::PointCloud2ConstPtr& cloud_msg)
{
// Container for original & filtered data
pcl::PCLPointCloud2* cloud = new pcl::PCLPointCloud2;
pcl::PCLPointCloud2ConstPtr cloudPtr(cloud);
pcl::PCLPointCloud2 cloud_filtered;
// Convert to PCL data type
pcl_conversions::toPCL(*cloud_msg, *cloud);
// Perform the actual filtering
pcl::VoxelGrid<pcl::PCLPointCloud2> sor;
sor.setInputCloud (cloudPtr);
sor.setLeafSize (0.1, 0.1, 0.1);
sor.filter (cloud_filtered);
// Convert to ROS data type
sensor_msgs::PointCloud2 output;
pcl_conversions::fromPCL(cloud_filtered, output);
// Publish the data
pub.publish (output);
}
int
main (int argc, char** argv)
{
// Initialize ROS
ros::init (argc, argv, "my_pcl_tutorial");
ros::NodeHandle nh;
// Create a ROS subscriber for the input point cloud
ros::Subscriber sub = nh.subscribe ("input", 1, cloud_cb);
// Create a ROS publisher for the output point cloud
pub = nh.advertise<sensor_msgs::PointCloud2> ("output", 1);
// Spin
ros::spin ();
}
Could it be that I need to manually download and put /narrow_stereo_textured/points2
in the same folder as example.cpp
? I assumed that it gets taken from the library, but maybe this assumption is wrong. If you need any further code or info, just tell me (you would have to give all instructions though).
I also had a problem incorporating the package before as can be read in http://answers.ros.org/question/24426... .
GDB bt output:
(gdb) bt
#0 0x00007ffff402ea70 in boost::math::lanczos::lanczos_initializer<boost::math::lanczos::lanczos17m64, long double>::init::init() ()
from /usr/lib/libpcl_sample_consensus.so.1.7
#1 0x00007ffff40066be in ?? () from /usr/lib/libpcl_sample_consensus.so.1.7
#2 0x00007ffff7dea10a in call_init (l=<optimized out>, argc=argc@entry=1,
argv=argv@entry=0x7fffffffd9c8, env=env@entry=0x7fffffffd9d8)
at dl-init.c:78
#3 0x00007ffff7dea1f3 in call_init (env=<optimized out>,
argv=<optimized out>, argc=<optimized out>, l=<optimized out>)
at dl-init.c:36
#4 _dl_init (main_map=0x7ffff7ffe1c8, argc=1, argv=0x7fffffffd9c8,
env=0x7fffffffd9d8) at dl-init.c:126
#5 0x00007ffff7ddb30a in _dl_start_user () from /lib64/ld-linux-x86-64.so.2
#6 0x0000000000000001 in ?? ()
#7 0x00007fffffffddd1 in ?? ()
#8 0x0000000000000000 in ?? ()
(gdb)
Probably easiest to run your node in GDB and debug it. You can do this either directly (starting the node binary from
lib
in yourdevel
space), or by using a launch prefix: wiki/roslaunch/nodes in gdb.Well, this is difficult for me to grasp. I built a launch file in
my_pcl_tutorial/launch
and tried to run it with the prefixes, but it did not work. Could you give step by step instructions for simply doing what I am supposed to do?The first would be to actually tell us what "did not work".
I never used GDB :>. Would
gdb example
invoked in thelib/my_pcl_tutorial
workspace be sufficient? The output is attached to the question. Additionally, I have not written launch files until yet and find it hard to transfer the launch files written in tutorials to my specific example.The launch file (probably something wrong there):
I am listening to gdb tutorials on youtube now. I am wondering if it is easier to debug with qtcreator.
gdb example
would work, yes. Start the rest of your application (ie: other nodes, and a roscore). After that, return togdb
, enterr
(short for run) and press enter. That should start your node. Wait for the crash, enterbt
(backtrace), enter. Copy/paste the backtrace in your question.Make sure to compile your node with debug symbols though.
And this may all seem overly complicated to solve your problem, but if you're going to be working in C/C++, knowing how to use
gdb
for tracking down a simpleSEGFAULT
is a really valuable skill.re: qt creator: also possible. But that is basically
gdb
with a UI.And your launch file "does not work", because you did not add the
launch-prefix
as the wiki page showed you. But if you don't need a set of nodes, then not using a launch file is also ok.I added the bt output. Regarding the launchfile, I thought the prefix was for commands (like -f, -type etc.), not for the file itself. What do you mean with compiling with debug symbols? Setting "break main" before running? I am thankful for your suggestions and see the importance of debugging.
launch-prefix
is an attribute of thenode
roslaunch element (see wiki/roslaunch/XML/node - Attributes). It is node specific, so you'll have to add it to the<node .. />
line in your launch file.As to your backtrace: your node was not compiled with debug symbols. You'll wan to compile your workspace (or at least the containing pkg) with something like
-DCMAKE_BUILD_TYPE=Debug
. Then try again.Just a guess: are you trying to compile & run this on a system with C++11 enabled by default, but are using PCL 1.7? If so, disable C++11 support: binary releases of PCL 1.7 are not compatible with that. See this Q/A for instance (note the bt).
I am still searching for a solution, but do not have access to my work laptop until Monday morning. I tried to replicate the issue with my personal computer on a virtual machine, but after invoking the command simply nothing happens, its pending. :>
Regarding the PCL 1.7 that could be the issue I guess. I am using ROS indigo/jade and according to http://www.ros.org/reps/rep-0003.html I should be using C++03. What is the easiest way to turn of C++11 in gcc? A few are here: http://stackoverflow.com/questions/16...
REP-3 just lists the requirements/conventions for ROS pkgs. Users (such as you) and external developers can do whatever they want. But in the PCL1.7-C++11 problem, it's a binary incompatibility between code compiled with C++11 enabled and the binary distribution of the PCL libs.
As to how to disable C++11: what I really meant is that you need to make sure that you're not inadvertently compiling with C++11 enabled. Newer GCC versions will do that, as will clang. You haven't given us any info on your platform or OS (or installed compilers), so that's a first thing to do.
The OS is Ubuntu 14.04 and the compiler is 99% gcc. I do CMake and build in qtcreator after writing the code.
I finally have my laptop back.
gcc -v
delivers: