首页 > 解决方案 > 链接第三个库时如何理解段错误的原因?

问题描述

我运行的程序会因段错误而崩溃,具体取决于我链接的库,我想了解在这种情况下通常可以采取哪些步骤来理解问题。

CMakeLists.txt程序运行良好时,文件如下所示:

add_exectuable(main main.cpp)
target_link_libraries(main ${PCL_Libraries})

相反,当我另外链接程序时Foo,程序会因段错误而崩溃。当程序尝试从硬盘加载点云时,会发生段错误。来自 gdb 的回溯如下:

>>> bt
#0  0x00007ffff7ef8198 in std::vector<pcl::PCLPointField, std::allocator<pcl::PCLPointField> >::_M_default_append(unsigned long) () from /usr/local/lib/libpcl_io.so.1.11
#1  0x00007ffff7ef6171 in pcl::PCDReader::readHeader(std::istream&, pcl::PCLPointCloud2&, Eigen::Matrix<float, 4, 1, 0, 4, 1>&, Eigen::Quaternion<float, 0>&, int&, int&, unsigned int&) () from /usr/local/lib/libpcl_io.so.1.11
#2  0x00007ffff7ef6aba in pcl::PCDReader::readHeader(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, pcl::PCLPointCloud2&, Eigen::Matrix<float, 4, 1, 0, 4, 1>&, Eigen::Quaternion<float, 0>&, int&, int&, unsigned int&, int) () from /usr/local/lib/libpcl_io.so.1.11
#3  0x00007ffff7ef3d04 in pcl::PCDReader::read(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, pcl::PCLPointCloud2&, Eigen::Matrix<float, 4, 1, 0, 4, 1>&, Eigen::Quaternion<float, 0>&, int&, int) () from /usr/local/lib/libpcl_io.so.1.11
#4  0x0000555555562819 in pcl::PCDReader::read<pcl::PointXYZRGB> (this=0x7fffffffdb20, file_name="/mnt/c/Users/fs/Documents/2017-02-16_KB/2017-02-16_KB_182332_REF_005524.pcd", cloud=..., offset=0) at /usr/local/include/pcl-1.11/pcl/io/pcd_io.h:280
#5  0x0000555555560c94 in pcl::io::loadPCDFile<pcl::PointXYZRGB> (file_name="/mnt/c/Users/fs/Documents/2017-02-16_KB/2017-02-16_KB_182332_REF_005524.pcd", cloud=...) at /usr/local/include/pcl-1.11/pcl/io/pcd_io.h:652
#6  0x000055555555c950 in main (argc=2, argv=0x7fffffffdcb8) at /home/fabian/work/benchmarking/cpp/bin/SerializeTransformations/main.cpp:33

此刻,我盯着屏幕,挠挠头,想知道我能做些什么来分析这个问题。我知道这个问题措辞含糊,因为我不知道如何剖析这些问题。在这种情况下,人们通常可以采取哪些步骤来开始理解问题?

标签: c++cmakecompilationlinkersegmentation-fault

解决方案


推荐阅读