ubuntu16-04+g2o

ubuntu16+g2o
步骤:
1)删除本机已经安装的g2o的可执行文件(https://github.com/RainerKuemmerle/g2o):

sudo rm -r /usr/local/lib/libg2o* /usr/local/include/g2o /usr/local/lib/g2o /usr/local/bin/g2o*


2)安装当前下载的g2o文件步骤(https://github.com/gaoxiang12/rgbd-slam-tutorial-gx/blob/master/g2o.zip):
安装依赖库:

sudo apt-get install libeigen3-dev libsuitesparse-dev libqt4-dev qt4-qmake libqglviewer-dev


安装:

cd g2o
mkdir build
cd build
cmake ..
make
sudo make install

3)cmake ..结果(如果报错,要么就是库没有安装合适,要么就是cmakeList.txt文件出错.或其他什么原因,主要是学会看报错内容.):

-- The C compiler identification is GNU 5.4.0
-- The CXX compiler identification is GNU 5.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Compiling on Unix
-- Found CHOLMOD: /usr/include/suitesparse  
-- Looking for sgemm_
-- Looking for sgemm_ - found
-- A library with BLAS API found.
-- Looking for cheev_
-- Looking for cheev_ - found
-- A library with LAPACK API found.
-- Found CHOLMOD and its dependencies
-- Found CSPARSE: /usr/include/suitesparse  
-- Try OpenMP C flag = [-fopenmp]
-- Performing Test OpenMP_FLAG_DETECTED
-- Performing Test OpenMP_FLAG_DETECTED - Success
-- Try OpenMP CXX flag = [-fopenmp]
-- Performing Test OpenMP_FLAG_DETECTED
-- Performing Test OpenMP_FLAG_DETECTED - Success
-- Found OpenMP: -fopenmp  
-- Found OpenGL: /usr/lib/x86_64-linux-gnu/libGL.so  
-- Compiling with OpenGL support
-- Looking for Q_WS_X11
-- Looking for Q_WS_X11 - found
-- Looking for Q_WS_WIN
-- Looking for Q_WS_WIN - not found
-- Looking for Q_WS_QWS
-- Looking for Q_WS_QWS - not found
-- Looking for Q_WS_MAC
-- Looking for Q_WS_MAC - not found
-- Found Qt4: /usr/bin/qmake (found version "4.8.7") 
-- Found QGLVIEWER: /usr/include/QGLViewer  
-- Compiling g2o apps
-- Compiling g2o examples
-- Compiling with GCC
-- Found Eigen3: /usr/include/eigen3 (Required is at least version "2.91.0") 
-- Configuring done
-- Generating done
-- Build files have been written to: /home/wangle/pcl/rgbd-slam-tutorial-gx-master/g2o/build


4)执行make命令生成可执行文件(这个过程中回存在很多问题需要我们一步一步的来改):

make

错误1---执行在31%时报错:
[ 31%] Building CXX object g2o/types/slam2d/CMakeFiles/types_slam2d.dir/edge_se2_pointxy_bearing.cpp.o
/home/wangle/pcl/rgbd-slam-tutorial-gx-master/g2o/g2o/types/slam2d/edge_se2_pointxy_bearing.cpp: In member function ‘virtual void g2o::EdgeSE2PointXYBearing::initialEstimate(const VertexSet&, g2o::OptimizableGraph::Vertex*)’:
/home/wangle/pcl/rgbd-slam-tutorial-gx-master/g2o/g2o/types/slam2d/edge_se2_pointxy_bearing.cpp:50:52: error: no matching function for call to ‘g2o::SE2::setRotation(Eigen::Rotation2D::Scalar)’
     t.setRotation(t.rotation().angle()+_measurement);
                                                    ^
In file included from /home/wangle/pcl/rgbd-slam-tutorial-gx-master/g2o/g2o/types/slam2d/vertex_se2.h:33:0,
                 from /home/wangle/pcl/rgbd-slam-tutorial-gx-master/g2o/g2o/types/slam2d/edge_se2_pointxy_bearing.h:31,
                 from /home/wangle/pcl/rgbd-slam-tutorial-gx-master/g2o/g2o/types/slam2d/edge_se2_pointxy_bearing.cpp:27:
/home/wangle/pcl/rgbd-slam-tutorial-gx-master/g2o/g2o/types/slam2d/se2.h:56:12: note: candidate: void g2o::SE2::setRotation(const Rotation2Dd&)
       void setRotation(const Rotation2Dd& R_) {_R=R_;}
            ^
/home/wangle/pcl/rgbd-slam-tutorial-gx-master/g2o/g2o/types/slam2d/se2.h:56:12: note:   no known conversion for argument 1 from ‘Eigen::Rotation2D::Scalar {aka double}’ to ‘const Rotation2Dd& {aka const Eigen::Rotation2D&}’
g2o/types/slam2d/CMakeFiles/types_slam2d.dir/build.make:206: recipe for target 'g2o/types/slam2d/CMakeFiles/types_slam2d.dir/edge_se2_pointxy_bearing.cpp.o' failed
make[2]: *** [g2o/types/slam2d/CMakeFiles/types_slam2d.dir/edge_se2_pointxy_bearing.cpp.o] Error 1
CMakeFiles/Makefile2:802: recipe for target 'g2o/types/slam2d/CMakeFiles/types_slam2d.dir/all' failed
make[1]: *** [g2o/types/slam2d/CMakeFiles/types_slam2d.dir/all] Error 2
Makefile:127: recipe for target 'all' failed
make: *** [all] Error 2

错误1----解决方法:

打开文件:./g2o/g2o/types/slam2d/edge_se2_pointxy_bearing.cpp文件

将代码:

t.setRotation(t.rotation().angle()+_measurement);
改成:
t.setRotation((Eigen::Rotation2Dd)(t.rotation().angle()+_measurement));

 

错误2:
[ 42%] Building CXX object g2o/apps/g2o_viewer/CMakeFiles/viewer_library.dir/g2o_qglviewer.cpp.o
/home/wangle/pcl/rgbd-slam-tutorial-gx-master/g2o/g2o/apps/g2o_viewer/g2o_qglviewer.cpp:46:13: error: conflicting return type specified for ‘virtual float g2o::{anonymous}::StandardCamera::zNear() const’
       float zNear() const {
             ^
In file included from /usr/include/QGLViewer/qglviewer.h:26:0,
                 from /home/wangle/pcl/rgbd-slam-tutorial-gx-master/g2o/g2o/apps/g2o_viewer/g2o_qglviewer.h:22,
                 from /home/wangle/pcl/rgbd-slam-tutorial-gx-master/g2o/g2o/apps/g2o_viewer/g2o_qglviewer.cpp:19:
/usr/include/QGLViewer/camera.h:231:16: error:   overriding ‘virtual qreal qglviewer::Camera::zNear() const’
  virtual qreal zNear() const;
                ^
/home/wangle/pcl/rgbd-slam-tutorial-gx-master/g2o/g2o/apps/g2o_viewer/g2o_qglviewer.cpp:53:13: error: conflicting return type specified for ‘virtual float g2o::{anonymous}::StandardCamera::zFar() const’
       float zFar() const
             ^
In file included from /usr/include/QGLViewer/qglviewer.h:26:0,
                 from /home/wangle/pcl/rgbd-slam-tutorial-gx-master/g2o/g2o/apps/g2o_viewer/g2o_qglviewer.h:22,
                 from /home/wangle/pcl/rgbd-slam-tutorial-gx-master/g2o/g2o/apps/g2o_viewer/g2o_qglviewer.cpp:19:
/usr/include/QGLViewer/camera.h:232:16: error:   overriding ‘virtual qreal qglviewer::Camera::zFar() const’
  virtual qreal zFar()  const;
                ^
g2o/apps/g2o_viewer/CMakeFiles/viewer_library.dir/build.make:80: recipe for target 'g2o/apps/g2o_viewer/CMakeFiles/viewer_library.dir/g2o_qglviewer.cpp.o' failed
make[2]: *** [g2o/apps/g2o_viewer/CMakeFiles/viewer_library.dir/g2o_qglviewer.cpp.o] Error 1
CMakeFiles/Makefile2:610: recipe for target 'g2o/apps/g2o_viewer/CMakeFiles/viewer_library.dir/all' failed
make[1]: *** [g2o/apps/g2o_viewer/CMakeFiles/viewer_library.dir/all] Error 2
Makefile:127: recipe for target 'all' failed
make: *** [all] Error 2

问题2解决方法:
用其他安装包中的g2o_qglviewer.cpp文件替换
路径为:
rgbd-slam-tutorial-gx-master/g2o/g2o/apps/g2o_viewer/g2o_qglviewer.cpp

 

问题3:
[ 68%] Building CXX object g2o/solvers/eigen/CMakeFiles/solver_eigen.dir/solver_eigen.cpp.o
In file included from /usr/include/eigen3/Eigen/Core:297:0,
                 from /usr/include/eigen3/Eigen/SparseCore:11,
                 from /usr/include/eigen3/Eigen/Sparse:26,
                 from /home/wangle/pcl/rgbd-slam-tutorial-gx-master/g2o/g2o/solvers/eigen/linear_solver_eigen.h:30,
                 from /home/wangle/pcl/rgbd-slam-tutorial-gx-master/g2o/g2o/solvers/eigen/solver_eigen.cpp:17:
/usr/include/eigen3/Eigen/src/Core/AssignEvaluator.h: In instantiation of ‘void Eigen::internal::call_assignment_no_alias(Dst&, const Src&, const Func&) [with Dst = Eigen::Matrix; Src = Eigen::Matrix; Func = Eigen::internal::assign_op]’:
/usr/include/eigen3/Eigen/src/Core/AssignEvaluator.h:712:27:   required from ‘void Eigen::internal::call_assignment(Dst&, const Src&, const Func&, typename Eigen::internal::enable_if<(! Eigen::internal::evaluator_assume_aliasing::value), void*>::type) [with Dst = Eigen::Matrix; Src = Eigen::Matrix; Func = Eigen::internal::assign_op; typename Eigen::internal::enable_if<(! Eigen::internal::evaluator_assume_aliasing::value), void*>::type = void*]’
/usr/include/eigen3/Eigen/src/Core/AssignEvaluator.h:693:18:   required from ‘void Eigen::internal::call_assignment(Dst&, const Src&) [with Dst = Eigen::Matrix; Src = Eigen::Matrix]’
/usr/include/eigen3/Eigen/src/Core/PlainObjectBase.h:682:32:   required from ‘Derived& Eigen::PlainObjectBase::_set(const Eigen::DenseBase&) [with OtherDerived = Eigen::Matrix; Derived = Eigen::Matrix]’
/usr/include/eigen3/Eigen/src/Core/Matrix.h:225:24:   required from ‘Eigen::Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>& Eigen::Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>::operator=(const Eigen::DenseBase&) [with OtherDerived = Eigen::Matrix; _Scalar = int; int _Rows = -1; int _Cols = 1; int _Options = 0; int _MaxRows = -1; int _MaxCols = 1]’
/usr/include/eigen3/Eigen/src/Core/PermutationMatrix.h:367:17:   required from ‘Eigen::PermutationMatrix& Eigen::PermutationMatrix::operator=(const Eigen::PermutationBase&) [with Other = Eigen::PermutationMatrix<-1, -1, long int>; int SizeAtCompileTime = -1; int MaxSizeAtCompileTime = -1; _StorageIndex = int]’
/home/wangle/pcl/rgbd-slam-tutorial-gx-master/g2o/g2o/solvers/eigen/linear_solver_eigen.h:66:18:   required from ‘void g2o::LinearSolverEigen::CholeskyDecomposition::analyzePatternWithPermutation(g2o::LinearSolverEigen::SparseMatrix&, const PermutationMatrix&) [with MatrixType = Eigen::Matrix; g2o::LinearSolverEigen::SparseMatrix = Eigen::SparseMatrix; g2o::LinearSolverEigen::PermutationMatrix = Eigen::PermutationMatrix<-1, -1, long int>]’
/home/wangle/pcl/rgbd-slam-tutorial-gx-master/g2o/g2o/solvers/eigen/linear_solver_eigen.h:193:9:   required from ‘void g2o::LinearSolverEigen::computeSymbolicDecomposition(const g2o::SparseBlockMatrix&) [with MatrixType = Eigen::Matrix]’
/home/wangle/pcl/rgbd-slam-tutorial-gx-master/g2o/g2o/solvers/eigen/linear_solver_eigen.h:98:37:   required from ‘bool g2o::LinearSolverEigen::solve(const g2o::SparseBlockMatrix&, double*, double*) [with MatrixType = Eigen::Matrix]’
/home/wangle/pcl/rgbd-slam-tutorial-gx-master/g2o/g2o/solvers/eigen/solver_eigen.cpp:109:1:   required from here
/usr/include/eigen3/Eigen/src/Core/util/StaticAssert.h:119:9: error: ‘YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY’ is not a member of ‘Eigen::internal::static_assertion
         if (Eigen::internal::static_assertion(CONDITION)>::MS
         ^
/usr/include/eigen3/Eigen/src/Core/util/XprHelper.h:707:3: note: in expansion of macro ‘EIGEN_STATIC_ASSERT’
   EIGEN_STATIC_ASSERT((internal::functor_is_product_like::ret \
   ^
/usr/include/eigen3/Eigen/src/Core/AssignEvaluator.h:745:3: note: in expansion of macro ‘EIGEN_CHECK_BINARY_COMPATIBILIY’
   EIGEN_CHECK_BINARY_COMPATIBILIY(Func,typename ActualDstTypeCleaned::Scalar,ty
   ^
g2o/solvers/eigen/CMakeFiles/solver_eigen.dir/build.make:62: recipe for target 'g2o/solvers/eigen/CMakeFiles/solver_eigen.dir/solver_eigen.cpp.o' failed
make[2]: *** [g2o/solvers/eigen/CMakeFiles/solver_eigen.dir/solver_eigen.cpp.o] Error 1
CMakeFiles/Makefile2:1682: recipe for target 'g2o/solvers/eigen/CMakeFiles/solver_eigen.dir/all' failed
make[1]: *** [g2o/solvers/eigen/CMakeFiles/solver_eigen.dir/all] Error 2
Makefile:127: recipe for target 'all' failed
make: *** [all] Error 2

 

问题3解决:
打开文件目录:g2o/g2o/solvers/eigen/linear_solver_eigen.h
 

template 
class LinearSolverEigen: public LinearSolver
 {
   public:
    typedef Eigen::SparseMatrix SparseMatrix;
    typedef Eigen::Triplet Triplet;
    typedef Eigen::PermutationMatrix PermutationMatrix;

 改成                                       
 template 
 class LinearSolverEigen: public LinearSolver
 {
  public:
    typedef Eigen::SparseMatrix SparseMatrix;    
 typedef Eigen::Triplet Triplet;

    typedef Eigen::PermutationMatrix PermutationMatrix;

问题4:
[ 73%] Building CXX object g2o/examples/tutorial_slam2d/CMakeFiles/tutorial_slam2d_library.dir/simulator.cpp.o
In file included from /usr/include/eigen3/Eigen/Core:297:0,
                 from /home/wangle/pcl/rgbd-slam-tutorial-gx-master/g2o/g2o/examples/tutorial_slam2d/se2.h:35,
                 from /home/wangle/pcl/rgbd-slam-tutorial-gx-master/g2o/g2o/examples/tutorial_slam2d/simulator.h:30,
                 from /home/wangle/pcl/rgbd-slam-tutorial-gx-master/g2o/g2o/examples/tutorial_slam2d/simulator.cpp:27:
/usr/include/eigen3/Eigen/src/Core/PlainObjectBase.h: In instantiation of ‘void Eigen::PlainObjectBase::_init1(Eigen::Index, typename Eigen::internal::enable_if<(((typename Eigen::internal::dense_xpr_base::type:: SizeAtCompileTime != 1) || (! Eigen::internal::is_convertible::Scalar>::value)) && ((! Eigen::internal::is_same::XprKind, Eigen::ArrayXpr>::value) || (typename Eigen::internal::dense_xpr_base::type:: SizeAtCompileTime == Eigen::Dynamic))), T>::type*) [with T = g2o::tutorial::Simulator::MotionType; Derived = Eigen::Matrix; Eigen::Index = long int; typename Eigen::internal::enable_if<(((typename Eigen::internal::dense_xpr_base::type:: SizeAtCompileTime != 1) || (! Eigen::internal::is_convertible::Scalar>::value)) && ((! Eigen::internal::is_same::XprKind, Eigen::ArrayXpr>::value) || (typename Eigen::internal::dense_xpr_base::type:: SizeAtCompileTime == Eigen::Dynamic))), T>::type = g2o::tutorial::Simulator::MotionType]’:
/usr/include/eigen3/Eigen/src/Core/Matrix.h:296:31:   required from ‘Eigen::Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>::Matrix(const T&) [with T = g2o::tutorial::Simulator::MotionType; _Scalar = double; int _Rows = -1; int _Cols = 1; int _Options = 0; int _MaxRows = -1; int _MaxCols = 1]’
/home/wangle/pcl/rgbd-slam-tutorial-gx-master/g2o/g2o/examples/tutorial_slam2d/simulator.cpp:78:39:   required from here
/usr/include/eigen3/Eigen/src/Core/util/StaticAssert.h:119:9: error: ‘FLOATING_POINT_ARGUMENT_PASSED__INTEGER_WAS_EXPECTED’ is not a member of ‘Eigen::internal::static_assertion
         if (Eigen::internal::static_assertion(CONDITION)>::MS
         ^
/usr/include/eigen3/Eigen/src/Core/PlainObjectBase.h:745:7: note: in expansion of macro ‘EIGEN_STATIC_ASSERT’
       EIGEN_STATIC_ASSERT(is_integer,
       ^
g2o/examples/tutorial_slam2d/CMakeFiles/tutorial_slam2d_library.dir/build.make:206: recipe for target 'g2o/examples/tutorial_slam2d/CMakeFiles/tutorial_slam2d_library.dir/simulator.cpp.o' failed
make[2]: *** [g2o/examples/tutorial_slam2d/CMakeFiles/tutorial_slam2d_library.dir/simulator.cpp.o] Error 1
CMakeFiles/Makefile2:1897: recipe for target 'g2o/examples/tutorial_slam2d/CMakeFiles/tutorial_slam2d_library.dir/all' failed
make[1]: *** [g2o/examples/tutorial_slam2d/CMakeFiles/tutorial_slam2d_library.dir/all] Error 2
Makefile:127: recipe for target 'all' failed
make: *** [all] Error 2
问题4解决方法:
删除rgbd-slam-tutorial-gx-master/g2o/g2o文件夹下的examples文件夹(注意删除相应的camkeList.txt文件中关于该文件夹的make语句)

# Examples
IF(G2O_BUILD_EXAMPLES)
  ADD_SUBDIRECTORY(examples)
ENDIF(G2O_BUILD_EXAMPLES)

 

在运行生成的可执行文件时:找不到这个libg2o_core.so的解决办法:

sudo gedit /etc/ld.so.conf(会打开一个文件)
/usr/local/lib(这行添加到打开的文件中保存)
sudo ldconfig(运行)

我遇到的就是如上的这5个问题.

你可能感兴趣的:(ubuntu16-04+g2o)