slam14讲-ch6-使用 g2o 拟合曲线编译问题记录
g2o版本
g2o- 20201223 _git
问题1
书中代码-适用于原版
Block:: LinearSolverType* linearSolver = new g2o:: LinearSolverDense< Block:: PoseMatrixType> ( ) ;
Block* solver_ptr = new Block ( linearSolver) ;
g2o:: OptimizationAlgorithmLevenberg* solver = new g2o:: OptimizationAlgorithmLevenberg ( solver_ptr ) ;
新版
unique_ptr< Block:: LinearSolverType> linearSolver ( new g2o:: LinearSolverDense< Block:: PoseMatrixType> ( ) ) ;
unique_ptr< Block> solver_ptr ( new Block ( std:: move ( linearSolver) ) ) ;
g2o:: OptimizationAlgorithmLevenberg* solver = new g2o:: OptimizationAlgorithmLevenberg ( std:: move ( solver_ptr) ) ;
问题2
# cmakelists
# 寻找 G2O 库
find_package ( G2O REQUIRED)
# 添加头文件
include_directories ( ${ G2O_INCLUDE_DIRS} )
target_link_libraries ( g2o_curve_fitting ${ G2O_CORE_LIBRARY} )
编译问题
/ usr/ bin/ ld: CMakeFiles/ g2o_curve_fitting. dir/ main. cpp. o: undefined reference to symbol '_ZN3g2o18get_monotonic_timeEv'
/ usr/ bin/ ld: / usr/ local/ lib/ libg2o_stuff. so: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
修改CMakeLists
# cmakelists
# 寻找 G2O 库
find_package ( G2O REQUIRED)
# 添加头文件
include_directories ( ${ G2O_INCLUDE_DIRS} )
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_curve_fitting ${ G2O_LIBS} )