在程序里用了
pcl::PassThrough<pcl::PointXYZ> pass;
pass.setInputCloud(cloud);
pass.setFilterFieldName("z");
pass.setFilterLimits(-1.2, 0);//保留或过滤z轴方向-1.2到0
pass.filter(*cloud_filtered);
这样一段代码,在ubuntu16.04的系统上运行没有问题,但是把程序放到ubuntu14.04上,能编译通过,但是一启动程序,程序直接挂掉,后面检查发现,在14.04上要这样实例化:pcl::PassThrough<pcl::PointXYZ>::Ptr pass ;程序才不会挂掉。
把pcl::PassThrough<pcl::PointXYZ>::Ptr pass ; 放在16.04上运行,程序又挂了,改成 pcl::PassThrough<pcl::PointXYZ> pass;就好了。
不懂原因。
gdb调试的时候发现错误:
0x00007ffff0266340 in boost::math::lanczos::lanczos_initializer<boost::math::lanczos::lanczos17m64, long double>::init::init() () from /usr/lib/libpcl_features.so.1.7
在网上发现了问题的其他解决方法。
因为在Cmake中使用了
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=gnu++0x")
这个是和boost是有冲突的,所以直接就不能使用了,解决方案就是尽量不使用c++11中新的特性。
在cmakelists里添加命令:
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O1")。
或者
如果要用C+11编译,则将程序该为release模式就可以跑了。
引用如下
To resolve this issue, you need to go a bit deeper. To my knowledge, it is caused by the differing boost implementations when compiling with c++11 and something else. As the PCl is not compiled with -std=c++11 option, it will contain different boost headers compared to rgbdslam. This results in segmentation fault on the initialization of boost.
To correct this, you need to compile PCL from their git repo (this change might be needed PointCloudLibrary/pcl#980). One way to make PCL compile with the c++11 option is to add this to the CMakeLists.txt: SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
When you have the PCL compiled, you need to make install, and change CMakeLists.txt on rgbdslam to use these libraries, this can be done by changing the line: find_package(PCL 1.7 REQUIRED COMPONENTS common io) to find_package(PCL 1.8 REQUIRED COMPONENTS common io)
问题与ros无关,是因为pcl1.7不支持c++11新特性。
参考:
https://stackoverflow.com/questions/26346690/debug-seg-fault-in-boostmathlanczos-with-libpcl-surface
https://blog.csdn.net/u014610460/article/details/85223960