我最近在学linux编程,在跑别人的程序的时候出现了错误,显示段错误,核心已经转储。请问我应该如何查找bug呢?

LeonSun_0101 2017-11-23 09:39:54
#include <iostream>
#include <iomanip>
using namespace std;

#include <Eigen/Core>
#include <Eigen/Geometry>
using namespace Eigen;

#include <pangolin/pangolin.h>

struct RotationMatrix
{
Matrix3d matrix = Matrix3d::Identity();
};

ostream& operator << ( ostream& out, const RotationMatrix& r )
{
out.setf(ios::fixed);
Matrix3d matrix = r.matrix;
out<<'=';
out<<"["<<setprecision(2)<<matrix(0,0)<<","<<matrix(0,1)<<","<<matrix(0,2)<<"],"
<< "["<<matrix(1,0)<<","<<matrix(1,1)<<","<<matrix(1,2)<<"],"
<< "["<<matrix(2,0)<<","<<matrix(2,1)<<","<<matrix(2,2)<<"]";
return out;
}

istream& operator >> (istream& in, RotationMatrix& r )
{
return in;
}

struct TranslationVector
{
Vector3d trans = Vector3d(0,0,0);
};

ostream& operator << (ostream& out, const TranslationVector& t)
{
out<<"=["<<t.trans(0)<<','<<t.trans(1)<<','<<t.trans(2)<<"]";
return out;
}

istream& operator >> ( istream& in, TranslationVector& t)
{
return in;
}

struct QuaternionDraw
{
Quaterniond q;
};

ostream& operator << (ostream& out, const QuaternionDraw quat )
{
auto c = quat.q.coeffs();
out<<"=["<<c[0]<<","<<c[1]<<","<<c[2]<<","<<c[3]<<"]";
return out;
}

istream& operator >> (istream& in, const QuaternionDraw quat)
{
return in;
}

int main ( int argc, char** argv )
{
pangolin::CreateWindowAndBind ( "visualize geometry", 1000, 600 );
glEnable ( GL_DEPTH_TEST );
pangolin::OpenGlRenderState s_cam (
pangolin::ProjectionMatrix ( 1000, 600, 420, 420, 500, 300, 0.1, 1000 ),
pangolin::ModelViewLookAt ( 3,3,3,0,0,0,pangolin::AxisY )
);

const int UI_WIDTH = 500;

pangolin::View& d_cam = pangolin::CreateDisplay().SetBounds(0.0, 1.0, pangolin::Attach::Pix(UI_WIDTH), 1.0, -1000.0f/600.0f).SetHandler(new pangolin::Handler3D(s_cam));

// ui
pangolin::Var<RotationMatrix> rotation_matrix("ui.R", RotationMatrix());
pangolin::Var<TranslationVector> translation_vector("ui.t", TranslationVector());
pangolin::Var<TranslationVector> euler_angles("ui.rpy", TranslationVector());
pangolin::Var<QuaternionDraw> quaternion("ui.q", QuaternionDraw());
pangolin::CreatePanel("ui")
.SetBounds(0.0, 1.0, 0.0, pangolin::Attach::Pix(UI_WIDTH));

while ( !pangolin::ShouldQuit() )
{
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

d_cam.Activate( s_cam );

pangolin::OpenGlMatrix matrix = s_cam.GetModelViewMatrix();
Matrix<double,4,4> m = matrix;
// m = m.inverse();
RotationMatrix R;
for (int i=0; i<3; i++)
for (int j=0; j<3; j++)
R.matrix(i,j) = m(j,i);
rotation_matrix = R;

TranslationVector t;
t.trans = Vector3d(m(0,3), m(1,3), m(2,3));
t.trans = -R.matrix*t.trans;
translation_vector = t;

TranslationVector euler;
euler.trans = R.matrix.transpose().eulerAngles(2,1,0);
euler_angles = euler;

QuaternionDraw quat;
quat.q = Quaterniond(R.matrix);
quaternion = quat;

glColor3f(1.0,1.0,1.0);

pangolin::glDrawColouredCube();
// draw the original axis
glLineWidth(3);
glColor3f ( 0.8f,0.f,0.f );
glBegin ( GL_LINES );
glVertex3f( 0,0,0 );
glVertex3f( 10,0,0 );
glColor3f( 0.f,0.8f,0.f);
glVertex3f( 0,0,0 );
glVertex3f( 0,10,0 );
glColor3f( 0.2f,0.2f,1.f);
glVertex3f( 0,0,0 );
glVertex3f( 0,0,10 );
glEnd();

pangolin::FinishFrame();
}
}
...全文
400 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
heronism 2017-11-29
  • 打赏
  • 举报
回复
引用 2 楼 zhao4zhong1 的回复:
进程意外退出会在当前目录下产生‘core’文件或形如‘core.数字’的文件比如‘core.1234’ 使用命令 gdb 运行程序名 core或core.数字 进入gdb然后使用bt命令 可以查看进程意外退出前函数调用的堆栈,内容为从上到下列出对应从里层到外层的函数调用历史。 如果进程意外退出不产生core文件,参考“ulimit -c core文件最大块大小”命令
向赵老师致敬!
老衲笑纳了 2017-11-29
  • 打赏
  • 举报
回复
段错误,个人经历:大多数都是环境改变的问题。
赵4老师 2017-11-24
  • 打赏
  • 举报
回复
进程意外退出会在当前目录下产生‘core’文件或形如‘core.数字’的文件比如‘core.1234’ 使用命令 gdb 运行程序名 core或core.数字 进入gdb然后使用bt命令 可以查看进程意外退出前函数调用的堆栈,内容为从上到下列出对应从里层到外层的函数调用历史。 如果进程意外退出不产生core文件,参考“ulimit -c core文件最大块大小”命令
zhxianbin 2017-11-23
  • 打赏
  • 举报
回复
学学 GDB !!!!!

23,121

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧