适配 openvslam和 slam14讲解代码版本
1. Eigen安装(最新3.3.7)
wget -q https://gitlab.com/libeigen/eigen/-/archive/3.3.7/eigen-3.3.7.tar.bz2 tar xf eigen-3.3.7.tar.bz2 rm -rf eigen-3.3.7.tar.bz2 cd eigen-3.3.7 mkdir -p build && cd build cmake \ -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_INSTALL_PREFIX=/usr/local \ .. make -j4 make install
2 g2o
不能下载最新版本,可能因为太新编译slam会报错
1:删除g2o的头文件,位于/usr/local/include/g2o下 sudo rm -r /usr/local/include/g2o 2:删除g2o的库文件,位于/usr/local/lib下 sudo rm -r /usr/local/lib/libg2o* 3:删除g2o的可执行文件,位于/usr/local/bin下 sudo rm -r /usr/local/bin/g2o*
下载老版本呢
https://codeload.github.com/RainerKuemmerle/g2o/zip/refs/tags/20200410_git
编译
报错的话直接 camke ..
mkdir build && cd build cmake \ -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_INSTALL_PREFIX=/usr/local \ -DCMAKE_CXX_FLAGS=-std=c++11 \ -DBUILD_SHARED_LIBS=ON \ -DBUILD_UNITTESTS=OFF \ -DBUILD_WITH_MARCH_NATIVE=ON \ -DG2O_USE_CHOLMOD=OFF \ -DG2O_USE_CSPARSE=ON \ -DG2O_USE_OPENGL=OFF \ -DG2O_USE_OPENMP=ON \ .. make -j8 make install
代码调用
默认安装没有把FindG2O.cmake一并放入系统盘,需要两种方式手动导入
简单方式1 指定安装包的FindG2O.cmake
工程
安装包
对应
list( APPEND CMAKE_MODULE_PATH "/home/r9000k/v1_software/openvslam/g2o-master/cmake_modules" ) #添加搜索路径
CMakeLists.txt
#声明要求的cmake最低版本 cmake_minimum_required(VERSION 3.0) project( SLAM ) set(CMAKE_BUILD_TYPE Release) set(CMAKE_CXX_FLAGS "-std=c++14 -O3") # OpenCV find_package(OpenCV REQUIRED) include_directories(${OpenCV_INCLUDE_DIRS}) # Eigen include_directories("/usr/include/eigen3") # g2o list( APPEND CMAKE_MODULE_PATH "/home/r9000k/v1_software/openvslam/g2o-master/cmake_modules" ) #添加搜索路径 find_package(G2O ) include_directories(${G2O_INCLUDE_DIRS}) SET(G2O_LIBRARIES ${G2O_STUFF_LIBRARY} ${G2O_CORE_LIBRARY} ${G2O_CLI_LIBRARY} ${G2O_SOLVER_CHOLMOD} ${G2O_SOLVER_CSPARSE} ${G2O_SOLVER_CSPARSE_EXTENSION} ${G2O_SOLVER_DENSE} ${G2O_SOLVER_PCG} ${G2O_SOLVER_SLAM2D_LINEAR} ${G2O_SOLVER_STRUCTURE_ONLY} ${G2O_SOLVER_EIGEN} ${G2O_TYPES_DATA} ${G2O_TYPES_ICP} ${G2O_TYPES_SBA} ${G2O_TYPES_SCLAM2D} ${G2O_TYPES_SIM3} ${G2O_TYPES_SLAM2D} ${G2O_TYPES_SLAM3D}) #给工程添加一个可执行程序 add_executable(SLAM main.cpp) #给工程链接库 # Eigen3就是一堆头文件没有连接库 target_link_libraries(SLAM ${OpenCV_LIBS}) target_link_libraries(SLAM ${CERES_LIBRARIES}) target_link_libraries(SLAM ${G2O_LIBRARIES} )
简单方式2 手动给文件
CMakeLists.txt
cmake_minimum_required(VERSION 3.1) project(untitled2) set(CMAKE_CXX_STANDARD 11) set(CMAKE_BUILD_TYPE Release) set(ALL_TARGET_LIBRARIES "") include(cmake/FindEigen3.cmake) include(cmake/FindG2O.cmake) add_executable(fit_curve fit_curve.cpp) target_link_libraries(fit_curve ${ALL_TARGET_LIBRARIES})
cmake/FindG2O.cmake
# Find the header files find_path(G2O_INCLUDE_DIR g2o/core/base_vertex.h ${G2O_ROOT}/include $ENV{G2O_ROOT}/include $ENV{G2O_ROOT} /usr/local/include /usr/include /opt/local/include /sw/local/include /sw/include NO_DEFAULT_PATH ) # Macro to unify finding both the debug and release versions of the # libraries; this is adapted from the OpenSceneGraph FIND_LIBRARY # macro. macro(FIND_G2O_LIBRARY MYLIBRARY MYLIBRARYNAME) find_library("${MYLIBRARY}_DEBUG" NAMES "g2o_${MYLIBRARYNAME}_d" PATHS ${G2O_ROOT}/lib/Debug ${G2O_ROOT}/lib $ENV{G2O_ROOT}/lib/Debug $ENV{G2O_ROOT}/lib NO_DEFAULT_PATH ) find_library("${MYLIBRARY}_DEBUG" NAMES "g2o_${MYLIBRARYNAME}_d" PATHS ~/Library/Frameworks /Library/Frameworks /usr/local/lib /usr/local/lib64 /usr/lib /usr/lib64 /opt/local/lib /sw/local/lib /sw/lib ) find_library(${MYLIBRARY} NAMES "g2o_${MYLIBRARYNAME}" PATHS ${G2O_ROOT}/lib/Release ${G2O_ROOT}/lib $ENV{G2O_ROOT}/lib/Release $ENV{G2O_ROOT}/lib NO_DEFAULT_PATH ) find_library(${MYLIBRARY} NAMES "g2o_${MYLIBRARYNAME}" PATHS ~/Library/Frameworks /Library/Frameworks /usr/local/lib /usr/local/lib64 /usr/lib /usr/lib64 /opt/local/lib /sw/local/lib /sw/lib ) if (NOT ${MYLIBRARY}_DEBUG) if (MYLIBRARY) set(${MYLIBRARY}_DEBUG ${MYLIBRARY}) endif (MYLIBRARY) endif (NOT ${MYLIBRARY}_DEBUG) endmacro(FIND_G2O_LIBRARY LIBRARY LIBRARYNAME) # Find the core elements FIND_G2O_LIBRARY(G2O_STUFF_LIBRARY stuff) FIND_G2O_LIBRARY(G2O_CORE_LIBRARY core) # Find the CLI library FIND_G2O_LIBRARY(G2O_CLI_LIBRARY cli) # Find the pluggable solvers FIND_G2O_LIBRARY(G2O_SOLVER_CHOLMOD solver_cholmod) FIND_G2O_LIBRARY(G2O_SOLVER_CSPARSE solver_csparse) FIND_G2O_LIBRARY(G2O_SOLVER_CSPARSE_EXTENSION csparse_extension) FIND_G2O_LIBRARY(G2O_SOLVER_DENSE solver_dense) FIND_G2O_LIBRARY(G2O_SOLVER_PCG solver_pcg) FIND_G2O_LIBRARY(G2O_SOLVER_SLAM2D_LINEAR solver_slam2d_linear) FIND_G2O_LIBRARY(G2O_SOLVER_STRUCTURE_ONLY solver_structure_only) FIND_G2O_LIBRARY(G2O_SOLVER_EIGEN solver_eigen) # Find the predefined types FIND_G2O_LIBRARY(G2O_TYPES_DATA types_data) FIND_G2O_LIBRARY(G2O_TYPES_ICP types_icp) FIND_G2O_LIBRARY(G2O_TYPES_SBA types_sba) FIND_G2O_LIBRARY(G2O_TYPES_SCLAM2D types_sclam2d) FIND_G2O_LIBRARY(G2O_TYPES_SIM3 types_sim3) FIND_G2O_LIBRARY(G2O_TYPES_SLAM2D types_slam2d) FIND_G2O_LIBRARY(G2O_TYPES_SLAM3D types_slam3d) # G2O solvers declared found if we found at least one solver set(G2O_SOLVERS_FOUND "NO") if (G2O_SOLVER_CHOLMOD OR G2O_SOLVER_CSPARSE OR G2O_SOLVER_DENSE OR G2O_SOLVER_PCG OR G2O_SOLVER_SLAM2D_LINEAR OR G2O_SOLVER_STRUCTURE_ONLY OR G2O_SOLVER_EIGEN) set(G2O_SOLVERS_FOUND "YES") endif (G2O_SOLVER_CHOLMOD OR G2O_SOLVER_CSPARSE OR G2O_SOLVER_DENSE OR G2O_SOLVER_PCG OR G2O_SOLVER_SLAM2D_LINEAR OR G2O_SOLVER_STRUCTURE_ONLY OR G2O_SOLVER_EIGEN) # G2O itself declared found if we found the core libraries and at least one solver set(G2O_FOUND "NO") if (G2O_STUFF_LIBRARY AND G2O_CORE_LIBRARY AND G2O_INCLUDE_DIR AND G2O_SOLVERS_FOUND) set(G2O_FOUND "YES") endif (G2O_STUFF_LIBRARY AND G2O_CORE_LIBRARY AND G2O_INCLUDE_DIR AND G2O_SOLVERS_FOUND) include_directories(SYSTEM ${G2O_INCLUDE_DIR}) list(APPEND ALL_TARGET_LIBRARIES ${G2O_TYPES_DATA} ${G2O_CORE_LIBRARY} ${G2O_STUFF_LIBRARY} ${G2O_SOLVER_PCG} ${G2O_SOLVER_CSPARSE} ${G2O_SOLVER_CHOLMOD} ${G2O_TYPES_SLAM3D} ${G2O_TYPES_SLAM3D_ADDONS})
标签:11,lib,SOLVER,local,LIBRARY,G2O,g2o,camke,FIND From: https://www.cnblogs.com/gooutlook/p/18310143