c++ - 链接第三个库时如何理解段错误的原因?
问题描述
我运行的程序会因段错误而崩溃,具体取决于我链接的库,我想了解在这种情况下通常可以采取哪些步骤来理解问题。
当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
此刻,我盯着屏幕,挠挠头,想知道我能做些什么来分析这个问题。我知道这个问题措辞含糊,因为我不知道如何剖析这些问题。在这种情况下,人们通常可以采取哪些步骤来开始理解问题?
解决方案
推荐阅读
- visual-studio - 如何从 cmake 发送 Visual Studio 配置选项
- r - 基于另一列的综合因子
- javascript - 直接在组件标签中编辑子组件的 props 值
- c++ - 为什么这个程序没有打印返回的迭代器的正确第二个元素?
- tensorflow - Tensorflow 如何处理转置卷积中的“相同”填充?
- mysql - 按字段选择记录顺序并按同一字段获取 SUM 组
- r - 是什么导致我的 R 包中的“必须从色调调色板中请求至少一种颜色”错误仅在基于 linux 的版本上?
- canvas - NativeScript-Vue 画布和 requestAnimationFrame
- php - 如何让 PHP 调用 shell 脚本?
- python - 未配置 Django 设置