G2O常见错误

问题1:

/usr/local/include/g2o/solvers/csparse/csparse_extension.h:27:10: fatal error: cs.h: 没有那个文件或目录
 #include 
          ^~~~~~
compilation terminated.
make[3]: *** [CMakeFiles/exm1.dir/bundle_adjustment_g2o.cpp.o] Error 1
make[2]: *** [CMakeFiles/exm1.dir/all] Error 2
make[1]: *** [CMakeFiles/exm1.dir/rule] Error 2
make: *** [exm1] Error 2

解决办法

此时我们打开终端 ,输入:

sudo apt-get install libsuitesparse-dev

如果已经安装完成,对suitesparse进行定位。

终端输入:

locate suitesparse

 定位结果:

G2O常见错误_第1张图片

可见,suitesparse中包含了cs.h文件。因此,我们只需要在CMAKELists中加入路径:

include_directories("/usr/include/suitesparse") 

 

问题2 :

CMake Error at CMakeLists.txt:10 (find_package):
  By not providing "FindCSparse.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "CSparse", but
  CMake did not find one.

  Could not find a package configuration file provided by "CSparse" with any
  of the following names:

    CSparseConfig.cmake
    csparse-config.cmake

  Add the installation prefix of "CSparse" to CMAKE_PREFIX_PATH or set
  "CSparse_DIR" to a directory containing one of the above files.  If
  "CSparse" provides a separate development package or SDK, be sure it has
  been installed.

解决方法:

主目录下搜索一下cmake_modules的位置.

list(APPEND CMAKE_MODULE_PATH /home/goocc/g2o-9b41a4ea5ade8e1250b9c1b279f3a9c098811b5a/cmake_modules) 
set(G2O_LIBS /usr/local/include/g2o)
FIND_PACKAGE( G2O REQUIRED )

问题3 :

 将如下代码

// 选择优化方法
    typedef g2o::BlockSolver_6_3 SlamBlockSolver; 
    typedef g2o::LinearSolverEigen< SlamBlockSolver::PoseMatrixType > SlamLinearSolver; 

    // 初始化求解器
    SlamLinearSolver* linearSolver = new SlamLinearSolver();
    linearSolver->setBlockOrdering( false );
    SlamBlockSolver* blockSolver = new SlamBlockSolver( linearSolver );
    g2o::OptimizationAlgorithmLevenberg* solver = new g2o::OptimizationAlgorithmLevenberg( blockSolver );

修改为:(注意括号)

 // 选择优化方法
    typedef g2o::BlockSolver> SlamBlockSolver;
    typedef g2o::LinearSolverEigen< SlamBlockSolver::PoseMatrixType > SlamLinearSolver;

    // 初始化求解器
    SlamLinearSolver* linearSolver = new SlamLinearSolver();
    linearSolver->setBlockOrdering( false );
    SlamBlockSolver* blockSolver = new SlamBlockSolver( std::unique_ptr(linearSolver) );
    g2o::OptimizationAlgorithmLevenberg* solver = new g2o::OptimizationAlgorithmLevenberg( std::unique_ptr(blockSolver));

问题4:

undefined reference to symbol 'cs_di_calloc'
//usr/lib/x86_64-linux-gnu/libcxsparse.so.3: 无法添加符号: DSO missing from command line

原因:

应该是缺少了cxsparse

target_link_libraries(pnp_g2o
    g2o_core g2o_stuff g2o_types_sba  
    g2o_types_slam3d 
    g2o_solver_csparse g2o_csparse_extension
    cholmod g2o_solver_cholmod
    cxsparse 
    ${OpenCV_LIBS}
${Sophus_LIBRARIES})

问题5:

未定以引用:

在函数‘g2o::LinearSolverCSparse >::init()’中:
pnp_g2o.cpp:(.text._ZN3g2o19LinearSolverCSparseIN5Eigen6MatrixIdLi6ELi6ELi0ELi6ELi6EEEE4initEv[_ZN3g2o19LinearSolverCSparseIN5Eigen6MatrixIdLi6ELi6ELi0ELi6ELi6EEEE4initEv]+0x11):对‘cs_di_sfree’未定义的引用
CMakeFiles/pnp_g2o.dir/pnp_g2o.cpp.o:在函数‘g2o::LinearSolverCSparse >::~LinearSolverCSparse()’中:
pnp_g2o.cpp:(.text._ZN3g2o19LinearSolverCSparseIN5Eigen6MatrixIdLi6ELi6ELi0ELi6ELi6EEEED2Ev[_ZN3g2o19LinearSolverCSparseIN5Eigen6MatrixIdLi6ELi6ELi0ELi6ELi6EEEED5Ev]+0x1b):对‘cs_di_sfree’未定义的引用

 增加连接库:

target_link_libraries(pnp_g2o
    g2o_core g2o_stuff g2o_types_sba  
    g2o_types_slam3d 
    g2o_solver_csparse g2o_csparse_extension
    cholmod g2o_solver_cholmod
    cxsparse 
    ${OpenCV_LIBS}
${Sophus_LIBRARIES})

附完整CMakeLists.txt

cmake_minimum_required(VERSION 2.8)
project(pnp_g2o)

set(CMAKE_BUILD_TYPE "Release")
add_definitions("-DENABLE_SSE")
set(CMAKE_CXX_FLAGS "-std=c++11 -O2 ${SSE_FLAGS} -msse4")

list(APPEND CMAKE_MODULE_PATH /home/goocc/g2o-9b41a4ea5ade8e1250b9c1b279f3a9c098811b5a/cmake_modules) 
set(G2O_LIBS /usr/local/include/g2o)

find_package(OpenCV 3 REQUIRED)
find_package(G2O REQUIRED)
find_package(Sophus REQUIRED)
# CSparse
find_package( CSparse REQUIRED)
include_directories( ${CSPARSE_INCLUDE_DIR} )

include_directories("/usr/include/suitesparse") 
include_directories(
        ${OpenCV_INCLUDE_DIRS}
        ${G2O_INCLUDE_DIRS}
        ${Sophus_INCLUDE_DIRS}
        "/usr/include/eigen3/"
)

add_executable(pnp_g2o pnp_g2o.cpp)
target_link_libraries(pnp_g2o
    g2o_core g2o_stuff g2o_types_sba  
    g2o_types_slam3d 
    g2o_solver_csparse g2o_csparse_extension
    cholmod g2o_solver_cholmod
    cxsparse 
    ${OpenCV_LIBS}
${Sophus_LIBRARIES})

附所有的头文件

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

你可能感兴趣的:(c++,开发语言)