问题现象
在学习高翔vslam 十四讲编译joinMap发现运行的时候会出现Segmentation fault (core dumped)
刚开始怀疑是编译的问题,确认本机的pcl已经安装完好,关于pcl的安装真的是一把雪一把泪,我刚开始安装这个链接来安装,发现还是不行
后面把源改成了清华,安装下面的这个教程就安装好了
https://blog.youkuaiyun.com/yingmai7741/article/details/86531850
后面一想,能够编译通过,肯定是代码的问题,后面一直debug,发现了问题所在,其主要为vector包含了一个数组类型为Eigen::Isometry3d,会导致core dump,下面为一个演示:
int main( int argc, char** argv )
{
vector<Eigen::Isometry3d> poses;
Eigen::Isometry3d T1=Eigen::Isometry3d::Identity();
for(int i=0;i<5;++i)
{
cout<<"i="<<i<<endl;
poses.push_back(T1);
}
上述的代码如果core dump的坏会报错:
joinMap: /usr/include/eigen3/Eigen/src/Core/DenseStorage.h:128: Eigen::internal::plain_array<T, Size, MatrixOrArrayOptions, 32>::plain_array() [with T = double; int Size = 16; int MatrixOrArrayOptions = 0]: Assertion `(internal::UIntPtr(eigen_unaligned_array_assert_workaround_gcc47(array)) & (31)) == 0 && "this assertion is explained here: " "http://eigen.tuxfamily.org/dox-devel/group__TopicUnalignedArrayAssert.html" " **** READ THIS WEB PAGE !!! ****"' failed.
Aborted (core dumped)
错误的意思我没太理解,反正就是说eigen适配c++11的STL vector容器有问题,需要加一些东西使用,链接如下
使用Eigen库和stl容器时遇到问题
英文的原文地址为:
http://eigen.tuxfamily.org/dox-devel/group__TopicUnalignedArrayAssert.html
按照上述的方法,可以在头文件部分添加:
EIGEN_DEFINE_STL_VECTOR_SPECIALIZATION(Eigen::Isometry3d)
或者使用的时候加上,见链接
vector<Eigen::Isometry3d, Eigen::aligned_allocator<Eigen::Isometry3d>> poses
这样,问题就修复了,可以开心的跑点云文件啦!!!