Ceres使用(一)

安装:

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编译路径。

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值