C+11编译调用PCL库时出现segmentation fault(core dumped)错误

最近在ros框架下调用PCL库,进行一些点云操作,编译没问题。但程序一执行便报错,提示如下:

segmentation fault(core dumped)

后来便单独写个小程序只调用PCL库,结果没有问题。经过仔细对比,发现在ros程序的CMakeLists.txt中,我加入了C+11编译的选项,删掉后则没问题。

原来在C+11下编译PCL还有这问题,于是在网上查了。如果要用C+11编译,则将程序该为release模式就可以跑了,即CMAKE_BUILD_TYPE设置为release。

最后在GitHub上找到了原因所在:

https://github.com/PointCloudLibrary/pcl/issues/619

https://github.com/PointCloudLibrary/pcl/issues?utf8=%E2%9C%93&q=segmentation+fault

引用如下

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)

还真是神奇,记录下来。

猜你喜欢

转载自blog.csdn.net/u014610460/article/details/85223960