C+11编译调用PCL库时出现segmentation fault(core dumped)错误
Posted lwlv
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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)
还真是神奇,记录下来。
以上是关于C+11编译调用PCL库时出现segmentation fault(core dumped)错误的主要内容,如果未能解决你的问题,请参考以下文章
Visual C++ 2017,外部“C”被忽略了吗?将 C++ 代码链接到 C 库时出现 LNK2019 错误