Tag Archives: Linked list

[Solved] G2o pointer error: error: no matching function for call to ‘g2o::BlockSolver

G2o pointer error

1. Problem description I

error: no matching function for call to ‘g2o::BlockSolver<g2o::BlockSolverTraits<-1, -1> >::BlockSolver(SlamLinearSolver*&)

And prompt

std::unique_ptr

The reason for the pointer may be a repeated reference.

G2oSolver::G2oSolver()
{
  // Step 1: Create a linear solver LinearSolver
  SlamLinearSolver *linearSolver = new SlamLinearSolver();
  linearSolver->setBlockOrdering(false);
  // Step 2: Create the BlockSolver and initialize it with the linear solver defined above
  SlamBlockSolver *blockSolver = new SlamBlockSolver(linearSolver);
  // Step 3: Create the total solver solver and select one from GN, LM, DogLeg and initialize it with the block solver BlockSolver defined above
  g2o::OptimizationAlgorithmLevenberg *solver = new g2o::OptimizationAlgorithmLevenberg(blockSolver);
  // Step 4: Create the sparse optimizer (SparseOptimizer)
  mOptimizer.setAlgorithm(solver);
}

Modified code:

G2oSolver::G2oSolver()
{
  // Step 1: Create a linear solver LinearSolver
  SlamLinearSolver *linearSolver = new SlamLinearSolver();
  linearSolver->setBlockOrdering(false);
  // Step 2: Create the BlockSolver and initialize it with the linear solver defined above
  SlamBlockSolver *blockSolver=new SlamBlockSolver(std::unique_ptr<SlamLinearSolver>(linearSolver));
  // Step 3: Create the total solver solver and select one from GN, LM, DogLeg and initialize it with the above block solver BlockSolver
  g2o::OptimizationAlgorithmLevenberg *solver = new g2o::OptimizationAlgorithmLevenberg(std::unique_ptr<SlamBlockSolver>( blockSolver));
  // Step 4: Create the Sparse Optimizer (SparseOptimizer)
  mOptimizer.setAlgorithm(solver);
}

2. Problem description II

fatal error: cs.h: No such file or directory

the error is in /usr/local/include/g2o/solvers/csparse/csparse_extension.h:

#include <cs.h>

Install
CSparse

sudo apt-get install libsuitesparse-dev

Find the header file

/usr/include/suitesparse/cs.h

add the header files in CMakeLists.txt:

include_directories("/usr/include/suitesparse") 
target_link_libraries(${PROJECT_NAME}_karto_slam_node
  ${catkin_LIBRARIES}
  ${Boost_LIBRARIES}
  sba
  ${CERES_LIBRARIES}
  gtsam

  ${G2O_LIBRARIES}
  ${SUITESPARSE_LIBRARIES}
)