Solve the error that some link libraries cannot be found when the generated program is running: error while loading shared libraries: libg2o_stuff.so: cannot open shared object file: No such file or directory
: 1. Install g2o to the system directory, 2. Add the library path /usr/local/ in /etc/ld.so.conf lib
- Compile and install g2o.
Project address: https://github.com/RainerKuemmerle/g2o
After compiling, it needs to besudo make install
installed in the system directory. - Add the path of the library in /etc/ld.so.conf
Add the following paths:sudo gedit /etc/ld.so.conf
implement/usr/local/lib
sudo ldconfig
- Write a CMakeLists.txt file and find the library through FindG2O.cmake.
Just compile and run.cmake_minimum_required(VERSION 3.14) project(g2oDemo) IF(NOT CMAKE_BUILD_TYPE) SET(CMAKE_BUILD_TYPE Release) ENDIF() MESSAGE("Build type: " ${CMAKE_BUILD_TYPE}) list(APPEND CMAKE_MODULE_PATH g2o路径/cmake_modules) # C++14 support set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD_REQUIRED ON) find_package(Eigen3 3.3 REQUIRED) find_package(G2O REQUIRED) include_directories(${G2O_INCLUDE_DIR}) message(STATUS "G2O_INCLUDE_DIR: ${G2O_INCLUDE_DIR}") message(STATUS "G2O_FOUND: ${G2O_FOUND}") 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(ba_demo ba_demo.cpp) target_link_libraries(ba_demo ${G2O_LIBRARIES})