I have a project which possesses and uses G2O library, it runs on both platforms(win/Unix).
(WINDOW PASSED / UNIX CRASHED)
We can see in both platforms, these lines:
g2o::SparseOptimizer optimizer;
g2o::BlockSolver_6_3::LinearSolverType * linearSolver;
linearSolver = new g2o::LinearSolverDense<g2o::BlockSolver_6_3::PoseMatrixType>();
Next steps, in window os we have this:
g2o::BlockSolver_6_3 * solver_ptr = new g2o::BlockSolver_6_3(linearSolver);
g2o::OptimizationAlgorithmLevenberg* solver = new g2o::OptimizationAlgorithmLevenberg(solver_ptr);
But Unix system can't compile those lines because it says
my_file_G2o.cpp: *In member function 'int Refiner_G2O::refinePose(cv::Mat&, const std::vector >&, const std::vector&, const cv::Mat&, float, std::vector&)': my_file_G2o.cpp --> no matching function for call to 'g2o::BlockSolver::BlockSolver(g2o::BlockSolver::LinearSolverType&)'* ^ In file included from G2o/include/g2o/core/block_solver.h:199:0, G2o/include/g2o/core/block_solver.hpp:40:1: note: candidate: g2o::BlockSolver::BlockSolver(std::unique_ptr) [with Traits = g2o::BlockSolverTraits<6, 3>; typename Traits::LinearSolverType = g2o::LinearSolver >] BlockSolver::BlockSolver(std::unique_ptr linearSolver)
When I see these errors, I complete my Unix code with this new block
auto solver_ptr = g2o::make_unique<g2o::BlockSolver_6_3>(linearSolver); // [SEGFAULT LINE]
auto solver = g2o::make_unique<g2o::OptimizationAlgorithmLevenberg>(solver_ptr);
optimizer.setAlgorithm(solver.get());
So now, I can build/run but I meet a segfault on the line with [SEGFAULT LINE] tag.
EDIT: After step to step debug with debug build I have a few news pieces of information:
g2o::SparseOptimizer optimizer; // debug says: "optimize: g2o::SparseOptimize
g2o::BlockSolver_6_3::LinearSolverType * linearSolver = NULL; // debug says : linearSolver: NULL
linearSolver = new g2o::LinearSolverDense<g2o::BlockSolver_6_3::PoseMatrixType>(); // debug says: linear solver: 0x7fe39cba9140
if (linearSolver == NULL) // debug says : not null.
exit (84);
auto solver_ptr = g2o::make_unique<g2o::BlockSolver< g2o::BlockSolver_6_3 >>(linearSolver);
// DEBUG --> And here, with "step into" he go to this "/usr/include/c++/6/bits/move.h" and in the ligne 48 we can see this function:
`template<typename T, typename ...ArgTs>
std::unique_ptr<T> make_unique(ArgTs&& ...args) //DEBUG says: args#0:
-var-create: unable to create variable object.
{
return std::unique_ptr<T>(g2o::make_unique<T>(std::forward<ArgTs>
(args)...));
};`
And he segfault because she have a bad args.
I don't understand, why? if someone has an idea I want to understand how in Window it works and not in Unix system, will feel wonderful if you help.
LINUX Version: Ubuntu 16.04
CMAKE Version: 3.11.4
Best regards,