A segmentation fault (core dumped) error occurs when C+11 compiles and calls the PCL library

Recently, the PCL library was called under the ros framework to perform some point cloud operations, and the compilation was fine. But as soon as the program is executed, an error is reported and the prompt is as follows:

segmentation fault(core dumped)

Later, I wrote a small program that only called the PCL library, and there was no problem. After careful comparison, I found that in the CMakeLists.txt of the ros program, I added the option of C+11 compilation. After deleting it, there is no problem.

It turns out that there is still this problem when compiling PCL under C+11, so I checked it online. If you want to compile with C+11, you can run the program in release mode, that is, set CMAKE_BUILD_TYPE to release.

Finally found the reason on GitHub:

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

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

Quote as follows

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)

 

It's really amazing, record it.

Guess you like

Origin blog.csdn.net/u014610460/article/details/85223960