我在编译的过程中,出现了以下的错误
-- Found AMD headers in: /usr/include/suitesparse
-- Found AMD library: /usr/lib/x86_64-linux-gnu/libamd.so
-- Found CAMD headers in: /usr/include/suitesparse
-- Found CAMD library: /usr/lib/x86_64-linux-gnu/libcamd.so
-- Found CCOLAMD headers in: /usr/include/suitesparse
-- Found CCOLAMD library: /usr/lib/x86_64-linux-gnu/libccolamd.so
-- Found CHOLMOD headers in: /usr/include/suitesparse
-- Found CHOLMOD library: /usr/lib/x86_64-linux-gnu/libcholmod.so
-- Found COLAMD headers in: /usr/include/suitesparse
-- Found COLAMD library: /usr/lib/x86_64-linux-gnu/libcolamd.so
-- Found SPQR headers in: /usr/include/suitesparse
-- Found SPQR library: /usr/lib/x86_64-linux-gnu/libspqr.so
-- Found Config headers in: /usr/include/suitesparse
-- Found Config library: /usr/lib/x86_64-linux-gnu/libsuitesparseconfig.so
-- Found Intel Thread Building Blocks (TBB) library (2020.1 / 11101) include location: . Assuming SuiteSparseQR was compiled with TBB.
-- Adding librt to SuiteSparse_config libraries (required on Linux & Unix [not OSX] if SuiteSparse is compiled with timing).
-- Could NOT find METIS (missing: METIS_INCLUDE_DIR METIS_LIBRARY)
CMake Error at /usr/local/lib/cmake/Ceres/CeresConfig.cmake:85 (message):
Failed to find Ceres - Missing required Ceres dependency: Eigen version
3.3.9, please set Eigen3_DIR.
Call Stack (most recent call first):
/usr/local/lib/cmake/Ceres/CeresConfig.cmake:214 (ceres_report_not_found)
CMakeLists.txt:11 (Find_Package)
CMake Error at CMakeLists.txt:11 (Find_Package):
Found package configuration file:
/usr/local/lib/cmake/Ceres/CeresConfig.cmake
but it set Ceres_FOUND to FALSE so package "Ceres" is considered to be NOT
FOUND.
-- Configuring incomplete, errors occurred!
See also "/home/cwj/slamebook2/ch9/build/CMakeFiles/CMakeOutput.log".
See also "/home/cwj/slamebook2/ch9/build/CMakeFiles/CMakeError.log".
仔细一看,应该是ceres和eigen3版本没有对上,根据ceres-solver的安装手册,具体查看:Installation — Ceres Solverhttp://ceres-solver.org/installation.html发现eigen3最少要是3.3.9,检查eigen3的版本:
pkg-config --modversion eigen3
发现eigen3的版本只是3.3.7,所以将其卸载,重新安装3.3.9的版本,然后编译成功,具体的CMakeLists:
cmake_minimum_required(VERSION 2.8)
project(bundle_adjustment)
set(CMAKE_BUILD_TYPE "Release")
set(CMAKE_CXX_FLAGS "-O3 -std=c++14")
LIST(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
include_directories("/usr/local/include/Eigen3")
Find_Package(G2O REQUIRED)
Find_Package(Eigen3 REQUIRED)
Find_Package(Ceres REQUIRED)
Find_Package(Sophus REQUIRED)
Find_Package(CSparse REQUIRED)
find_package(fmt REQUIRED)
SET(G2O_LIBS g2o_csparse_extension g2o_stuff g2o_core cxsparse)
include_directories(${PROJECT_SOURCE_DIR} ${EIGEN3_INCLUDE_DIR} ${CSPARSE_INCLUDE_DIR})
add_library(bal_common common.cpp)
add_executable(bundle_adjustment_g2o bundle_adjustment_g2o.cpp)
add_executable(bundle_adjustment_ceres bundle_adjustment_ceres.cpp)
target_link_libraries(bundle_adjustment_ceres ${CERES_LIBRARIES} bal_common)
target_link_libraries(bundle_adjustment_g2o ${G2O_LIBS} bal_common fmt)
具体运行结果: