先对g2o的依赖库进行安装:
sudo apt-get update
sudo apt-get install libeigen3-dev
sudo apt-get install libsuitesparse-dev
sudo apt-get install qtdeclarative5-dev
sudo apt-get install qt5-qmake
sudo apt-get install libqglviewer-dev-qt5
然后下载g2o(2020那个版本)
地址:https://github.com/RainerKuemmerle/g2o/tree/20200410_git
然后在解压后的g2o文件目录下输入:
mkdir build
cd build
sudo ldconfig
cmake ..
make j2
CMakeLists.txt引用g2o:
LIST( APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake_modules )
SET( G2O_ROOT /usr/local/include/g2o )
find_package(G2O REQUIRED)
include_directories(${G2O_INCLUDE_DIRS})
add_executable(g2oCurveFitting g2oCurveFitting.cpp)
target_link_libraries(g2oCurveFitting g2o_core g2o_stuff ${OpenCV_LIBS})
之后编译时出现下面问题
Please set them or make sure they are set and tested correctly in the CMake files: G2O_INCLUDE_DIRS
used as include directory in directory /home/xj/slambook2-master/ch6
used as include directory in directory /home/xj/slambook2-master/ch6
used as include directory in directory /home/xj/slambook2-master/ch6
是因为cmake_modules写成了cmake_module
其它链接:Ubuntu16.04安装视觉SLAM环境(g2o)