本文仅用于记录自己在学习Ceres时遇到的困难。
0. 参考
Ceres官网:http://ceres-solver.org/installation.html
github: https://github.com/ceres-solver/ceres-solver
1. 下载
从github下载最新的ceres
git clone https://ceres-solver.googlesource.com/ceres-solver
2. 安装依赖
# CMake
sudo apt-get install cmake
# google-glog + gflags
sudo apt-get install libgoogle-glog-dev
# BLAS & LAPACK
sudo apt-get install libatlas-base-dev
# Eigen3
sudo apt-get install libeigen3-dev
# SuiteSparse and CXSparse (optional)
# - If you want to build Ceres as a *static* library (the default)
# you can use the SuiteSparse package in the main Ubuntu package
# repository:
sudo apt-get install libsuitesparse-dev
# - However, if you want to build Ceres as a *shared* library, you must
# add the following PPA:
sudo add-apt-repository ppa:bzindovic/suitesparse-bugfix-1319687
sudo apt-get update
sudo apt-get install libsuitesparse-dev
3. 编译
首先解压文件,然后三连。
mkdir build
cd build
cmake ..
make -j4
make install
注意在编译过程中,Ceres依赖Eigen库的,所以会自动检查eigen是否符合要求。当前最新版要求Eigen版本高于3.3才能安装。如果低,请自行下载eigen编译安装。
补充查看eigen版本的方法
cd /usr/local/include/eigen3/Eigen/src/Core/util # 切到路径
vim Macros.h # 打开宏定义头文件
里面最上面几行EIGEN_XXXX_VERSION 表示了版本(图为3.3.7)
4. 写CMakeLists.txt
关键部分:
find_package(Ceres REQUIRED)
include_directories(${CERES_INCLUDE_DIRS})
target_link_libraries(project ${CERES_LIBRARIES})
5. Bugs
最开始在执行cmake …编译CMakeLists.txt时报错:
CMake Error at /usr/share/cmake-3.5/Modules/CMakeFindDependencyMacro.cmake:45 (message):
Invalid arguments to find_dependency
Call Stack (most recent call first):
/usr/local/lib/cmake/Ceres/CeresConfig.cmake:175 (find_dependency)
CMakeLists.txt:14 (find_package)
表示在CMakeLists里面(find_package)时出了错误,还专门去查看了CeresConfig.cmake文件的第175行,
没有问题,和Eigen版本相同。后来发现了问题所在:
cmake在3.5之后有过调整,修改了find_dependency() 的参数,所以时cmake版本问题。
于是重新安装了最新版的cmake-3.16(然而apt上最新还是3.5),
问题解决。