问题:
undefined reference to symbol 'cs_di_calloc'
//usr/lib/x86_64-linux-gnu/libcxsparse.so.3: 无法添加符号: DSO missing from command line
原因:
应该是缺少了cxsparse
解决方法:
在CMakeLists.txt里最后面添加:
SET(G2O_LIBS g2o_cli g2o_ext_freeglut_minimal g2o_simulator g2o_solver_slam2d_linear g2o_types_icp g2o_types_slam2d g2o_core g2o_interface g2o_solver_csparse g2o_solver_structure_only g2o_types_sba g2o_types_slam3d g2o_csparse_extension g2o_opengl_helper g2o_solver_dense g2o_stuff g2o_types_sclam2d g2o_parser g2o_solver_pcg g2o_types_data g2o_types_sim3 cxsparse )
target_link_libraries(g2o_test ${G2O_LIBS})
参考来源:
g2o最新版本使用LinearSolverCSparse时出错 · Issue #103 · gaoxiang12/slambook · GitHub
问题:
error: 'index_sequence' is not a member of 'std'
原因:
SLAM十四讲中,编译带g2o库的文件采用C++ 11,而最新的g2o库采用了C++ 14的特性。
解决方法:
在CMakeLists.txt里添加,或者把原来的11改成14:
set(CMAKE_CXX_STANDARD 14)
参考来源:https://blog.csdn.net/weixin_44023934/article/details/122112827
问题:
no matching function for call to ‘g2o::BlockSolver<g2o::BlockSolverTraits<3, 1> >::BlockSolver(g2o::BlockSolver<g2o::BlockSolverTraits<3, 1> >::LinearSolverType*&)’
原因:
g2o版本对不上,SLAM书上和Github下载的g2o版本不对应。
解决方法:
原代码:
// 构建图优化,先设定g2o
typedef g2o::BlockSolver< g2o::BlockSolverTraits<3,1> > Block; // 每个误差项优化变量维度为3,误差值维度为1
Block::LinearSolverType* linearSolver = new g2o::LinearSolverDense<Block::PoseMatrixType>(); // 线性方程求解器
Block* solver_ptr = new Block( linearSolver ); // 矩阵块求解器
// 梯度下降方法,从GN, LM, DogLeg 中选
g2o::OptimizationAlgorithmLevenberg* solver = new g2o::OptimizationAlgorithmLevenberg( solver_ptr );
// g2o::OptimizationAlgorithmGaussNewton* solver = new g2o::OptimizationAlgorithmGaussNewton( solver_ptr );
// g2o::OptimizationAlgorithmDogleg* solver = new g2o::OptimizationAlgorithmDogleg( solver_ptr );
g2o::SparseOptimizer optimizer; // 图模型
optimizer.setAlgorithm( solver ); // 设置求解器
optimizer.setVerbose( true ); // 打开调试输出
修改为:
// 构建图优化,先设定g2o
typedef g2o::BlockSolver< g2o::BlockSolverTraits<3,1> > Block; // 每个误差项优化变量维度为3,误差值维度为1
std::unique_ptr<Block::LinearSolverType> linearSolver(new g2o::LinearSolverDense<Block::PoseMatrixType>()); // 线性方程求解器
std::unique_ptr<Block> solver_ptr (new Block(std::move(linearSolver))); // 矩阵块求解器
// 梯度下降方法,从GN, LM, DogLeg 中选
g2o::OptimizationAlgorithmLevenberg* solver = new g2o::OptimizationAlgorithmLevenberg(std::move(solver_ptr));
// g2o::OptimizationAlgorithmGaussNewton* solver = new g2o::OptimizationAlgorithmGaussNewton(std::move(solver_ptr));
// g2o::OptimizationAlgorithmDogleg* solver = new g2o::OptimizationAlgorithmDogleg(std::move(solver_ptr));
g2o::SparseOptimizer optimizer; // 图模型
optimizer.setAlgorithm( solver ); // 设置求解器
optimizer.setVerbose( true ); // 打开调试输出
参考来源:
https://blog.csdn.net/yongniao9185/article/details/112299119
问题:
error: ‘LinearSolverCSparse’ in namespace ‘g2o’ does not name a template type
源代码为:
std::unique_ptr<Block::LinearSolverType> linearSolver ( new g2o::LinearSolverCSparse<Block::PoseMatrixType>());
解决方法:
添加头文件:
#include <g2o/solvers/csparse/linear_solver_csparse.h>
问题:‘VertexSBAPointXYZ’ is not a member of ‘g2o’
原因:新版g2o库中不再存在原先的VertexSBAPointXYZ
解决方法:
将所有报错的地方改为VertexPointXYZ
参考来源:在PnP后进行BA优化和使用G2O中所遇到的问题总结_不加辣先生的博客-CSDN博客
问题:
打开g2o_viewer时,g2o_viewer:未找到命令
原因:
在对g2o进行cmake时,会出现如下图的提示:Found unsuitable Qt version 和 Cound NOT find QGLVIEWER
解决方法:
首先删除qt4,再安装qt5,并装依赖库
sudo apt-get remove qt4-qmake
sudo apt-get install qt5-default qtcreator
sudo apt-get install libqglviewer-dev-qt5
重新cmake
cmake ..
出现以下情况就说明找到库了
重新编译安装
make -j4
sudo make install
就可以了。
参考来源:
https://blog.csdn.net/qq_40424333/article/details/117449996
问题:
对‘Sophus::SO3::log() const’未定义的引用
原因:
安装Sophus时,有个lib文件“libSophus.so”会出现在/usr/local/lib/libSophus.so
解决方法:
在CMakeList.txt文件中添加:
set(Sophus_LIBRARIES libSophus.so)
参考文献:https://blog.csdn.net/u010003609/article/details/68961293
问题:
打开g2o_viewer时出现以下报错:
g2o_viewer: error while loading shared libraries: libg2o_viewer.so: cannot open shared object file: No such file or directory
原因:
在默认情况下,编译器只会使用/lib和/usr/lib这两个目录下的库文件,通过源码包进行安装时,如果不指定--prefix会将库安装在/usr/local目录下,而又没有在文件/etc/ld.so.conf中添加 /usr/local/lib这个目录。
解决方法:
打开并编辑这个文件:
sudo gedit /etc/ld.so.conf
然后添加 /usr/local/lib这个目录:
include /usr/local/lib
之后运行(必不可少)
sudo ldconfig
参考来源: