安装:
1.下载源码:
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.在下载好的Ceres源码文件中,用cmake形式编译。
# in ceres-solver directory
mkdir build
cd build
cmake ..
make -j4
sudo make install(optional)
4.指定路径安装
可以通过指定安装路径,把Ceres安装在非系统路径下:-DCMAKE_INSTALL_PREFIX="/some/where/local",这样在cmake中使用时,就需要指定这个路径:
find_package(Ceres REQUIRED PATHS "/some/where/local/")
在CMake中使用Ceres
为了在CMake中通过find_package()使用Ceres,可通过以下两种方式:
1.编译Ceres时必须通过sudo make install安装;
2.ceres的编译目录在配置时,通过EXPORT_BUILD_DIR选项导出。
以examples/helloworld.cc为例展示其在CMake中的使用:
cmake_minimum_required(VERSION 2.8)
project(helloworld)
find_package(Ceres REQUIRED)
include_directories(${CERES_INCLUDE_DIRS})
# helloworld
add_executable(helloworld helloworld.cc)
target_link_libraries(helloworld ${CERES_LIBRARIES})
无论Ceres是安装还是导出,如果检测到多个版本,通过设置Ceres_DIR来控制用哪个版本。如果Ceres是安装方式,Ceres_DIR应该是包含了安装文件CeresConfig.cmake的路径,例如/usr/local/share/Ceres。如果Ceres是导出方式,Ceres_DIR应该是导出的Ceres编译路径。