安装ceres到别的地方该如何配置
ceres库是算法优化库,与g2o不同的是它需要自己搭建代价函数,高翔博士那本书上安装ceres默认是装在(/usr/local/include和/usr/local/lib)中。
原书CmakeList.txt是:
list( APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake_modules )
# 寻找Ceres库并添加它的头文件
find_package( ceres REQUIRED PATHS )
include_directories( ${CERES_INCLUDE_DIRS})
link_directories(${CERES_LIBRARY_DIRS}))
# OpenCV
find_package( OpenCV REQUIRED )
include_directories( ${OpenCV_DIRS} )
add_executable( curve_fitting main.cpp )
# 与Ceres和OpenCV链接
target_link_libraries( curve_fitting ${CERES_LIBRARIES} ${OpenCV_LIBS} )
但是如果我们把ceres安装到别处,那么上述的CmakeList.txt在搭建程序的时候会报错:
Could not find a package configuration file provided by "Ceres" with any of
the following names:
CeresConfig.cmake
ceres-config.cmake
Add the installation prefix of "Ceres" to CMAKE_PREFIX_PATH or set
"Ceres_DIR" to a directory containing one of the above files. If "Ceres"
provides a separate development package or SDK, be sure it has been
installed.
整个安装ceres 和配置ceres过程
1、下载ceres
2、根据http://ceres-solver.org/installation.html 来安装ceres
安装到别处的方法是
mkdir build
cd build
cmake -D CMAKE_INSTALL_PREFIX=/usr/local/ceres .. #前提是在local下自己建立了一个ceres文件
sudo make install
安装后的效果如下图:
3、对于以上CmakeList.txt文件中修改为:
#list( APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake_modules )#可有可无
set(Ceres_DIR /usr/local/ceres/lib/cmake/Ceres) #important,/usr/local/ceres这种还是报错,要到Ceres才行
find_package(Ceres REQUIRED )
include_directories(${CERES_INCLUDE_DIRS})
link_directories(${CERES_LIBRARY_DIRS})
add_executable( curve_fitting main.cpp )
target_link_libraries( curve_fitting ${CERES_LIBRARIES})