Windows安装Ceres
综述
Ceres Solver is an open source C++ library for modeling and solving large, complicated optimization problems. It can be used to solve Non-linear Least Squares problems with bounds constraints and general unconstrained optimization problems. It is a mature, feature rich, and performant library that has been used in production at Google since 2010.
Ceres Solver 是一个用于建模和解决大型复杂优化问题的开源c++库。它可用于求解有界约束的非线性最小二乘问题和一般无约束优化问题。它是一个成熟的、功能丰富的、高性能的库,从2010年开始在谷歌的生产环境中使用。
本文首先给出安装各个包的前提,然后针对每一个包的安装我们都给出了相关的安装步骤文章。
如遇任何问题欢迎随时联络: aaa@qq.com
前提
- Ceres-solver 1.14.0(本文)
- Eigen3
Eigen3教程 - gflags
gflags 教程 - glog
glog 教程 - suitesparse-metis-for-windows Release 1.3.1
suitesparse 教程
注意:suitesparse教程中不推荐大家自己全部自己配置再cmake。
步骤
编译安装Ceres
下载Ceres 1.14.0
下载
下载zip后解压即可,然后使用cmake编译。
设置配置信息
使用cmake首先configuration一下。
然后会出错。
然后配置你的文件,请确保你的配置文件如下:
注意:这里的SP_ROOT就是大家下载的suitesparse,SP_ROOT_output就是大家使用cmake编译后的suitesparse文件。
注意有一些项原来的cmake配置中没有需要手动添加。
你会发现configuration结束后:我们所有需要的库都被found了。
Selecting Windows SDK version to target Windows 10.0.17763.
Detected Ceres version: 1.14.0 from C:/local/ceres-solver-1.14.0/include/ceres/version.h
-- Disabling tests. The flags BUILD_TESTING and BUILD_SHARED_LIBS are incompatible with MSVC.
No preference for use of exported Eigen CMake configuration set, and no hints for include directory provided. Defaulting to preferring an installed/exported Eigen CMake configuration if available.
Found installed version of Eigen: C:/Program Files (x86)/Eigen3/share/eigen3/cmake
-- Found Eigen version 3.3.7: C:/Program Files (x86)/Eigen3/include/eigen3
-- Enabling use of Eigen as a sparse linear algebra library.
Found BLAS: C:/local/SP_ROOT/lapack_windows/x64/libblas.lib
-- Found LAPACK library: C:/local/SP_ROOT/lapack_windows/x64/liblapack.lib
Found AMD headers in: C:/local/SP_ROOT_output/install/include/suitesparse
Found AMD library: C:/local/SP_ROOT_output/install/lib64/libamd.lib
Found CAMD headers in: C:/local/SP_ROOT_output/install/include/suitesparse
Found CAMD library: C:/local/SP_ROOT_output/install/lib64/libcamd.lib
Found COLAMD headers in: C:/local/SP_ROOT_output/install/include/suitesparse
Found COLAMD library: C:/local/SP_ROOT_output/install/lib64/libcolamd.lib
Found CCOLAMD headers in: C:/local/SP_ROOT_output/install/include/suitesparse
Found CCOLAMD library: C:/local/SP_ROOT_output/install/lib64/libccolamd.lib
Found CHOLMOD headers in: C:/local/SP_ROOT_output/install/include/suitesparse
Found CHOLMOD library: C:/local/SP_ROOT_output/install/lib64/libcholmod.lib
Found SUITESPARSEQR headers in: C:/local/SP_ROOT_output/install/include/suitesparse
Found SUITESPARSEQR library: C:/local/SP_ROOT_output/install/lib64/libspqr.lib
Did not find Intel TBB library, assuming SuiteSparseQR was not compiled with TBB.
Found SUITESPARSE_CONFIG headers in: C:/local/SP_ROOT_output/install/include/suitesparse
Found SUITESPARSE_CONFIG library: C:/local/SP_ROOT_output/install/lib64/suitesparseconfig.lib
Found METIS library: C:/local/SP_ROOT_output/install/lib64/metis.lib
Found SuiteSparse: TRUE (found version "4.4.4")
-- Found SuiteSparse 4.4.4, building with SuiteSparse.
-- Building without CXSparse.
No preference for use of exported gflags CMake configuration set, and no hints for include/library directories provided. Defaulting to preferring an installed/exported gflags CMake configuration if available.
Found installed version of gflags: C:/Program Files (x86)/gflags/lib/cmake/gflags
Detected gflags version: 2.2.2
-- Found Google Flags header in: C:/Program Files (x86)/gflags/include, in namespace: google
No preference for use of exported glog CMake configuration set, and no hints for include/library directories provided. Defaulting to preferring an installed/exported glog CMake configuration if available.
Found installed version of glog: C:/Program Files (x86)/glog/lib/cmake/glog
Detected glog version: 0.4.0
-- Found Google Log (glog). Assuming glog was built with gflags support as gflags was found. This will make gflags a public dependency of Ceres.
-- Building with OpenMP.
Looking for C++ include unordered_map
Looking for C++ include unordered_map - found
Performing Test HAVE_UNORDERED_MAP_IN_STD_NAMESPACE
Performing Test HAVE_UNORDERED_MAP_IN_STD_NAMESPACE - Success
-- Found unordered_map/set in std namespace.
Looking for C++ include memory
Looking for C++ include memory - found
Performing Test HAVE_SHARED_PTR_IN_STD_NAMESPACE
Performing Test HAVE_SHARED_PTR_IN_STD_NAMESPACE - Success
-- Found shared_ptr in std namespace using <memory> header.
Performing Test CXX11_MATH_FUNCTIONS_FOUND
Performing Test CXX11_MATH_FUNCTIONS_FOUND - Success
==============================================================
Compiling Ceres using C++11. This will result in a version
of Ceres that will require the use of C++11 in client code.
==============================================================
-- Building Ceres as a shared library.
Enabling CERES_USE_EIGEN_SPARSE in Ceres config.h
Enabling CERES_NO_CXSPARSE in Ceres config.h
Enabling CERES_USE_CXX11 in Ceres config.h
Enabling CERES_USE_OPENMP in Ceres config.h
Enabling CERES_STD_UNORDERED_MAP in Ceres config.h
Enabling CERES_USING_SHARED_LIBRARY in Ceres config.h
Enabling CERES_MSVC_USE_UNDERSCORE_PREFIXED_BESSEL_FUNCTIONS in Ceres config.h
-- Build the examples.
Configuring done
Generating done
点击generate。
然后在VS中使用release模式生成ALL_BUILD和INSTALL。
使用管理员身份运行,不然会报错:
- 首先是ALL_BUILD
这个过程非常慢!
- 然后是INSTALL
完毕后,我们需要切换到debug模式:
切换到Debug模式。然后右键单击“ceres”项目->属性->链接器->输入->附加依赖项。
右键属性:
这里要注意属性管理也应设为Debug模式。
将以下7个Release版本的库改为Debug版本的库
C:\local\SP_ROOT_output\install\lib\libspqr.lib
C:\local\SP_ROOT_output\install\lib\libcholmod.lib
C:\local\SP_ROOT_output\install\lib\libccolamd.lib
C:\local\SP_ROOT_output\install\lib\libcamd.lib
C:\local\SP_ROOT_output\install\lib\libcolamd.lib
C:\local\SP_ROOT_output\install\lib\libamd.lib
C:\local\SP_ROOT_output\install\lib\suitesparseconfig.lib
调整为Debug版本库:(区别就是最后面会多一个d)
C:\local\SP_ROOT_output\install\lib\libspqrd.lib
C:\local\SP_ROOT_output\install\lib\libcholmodd.lib
C:\local\SP_ROOT_output\install\lib\libccolamdd.lib
C:\local\SP_ROOT_output\install\lib\libcamdd.lib
C:\local\SP_ROOT_output\install\lib\libcolamdd.lib
C:\local\SP_ROOT_output\install\lib\libamdd.lib
C:\local\SP_ROOT_output\install\lib\suitesparseconfigd.lib
然后生成ALL_BUILD和INSTALL项目,完成Debug模式的编译和安装过程。
注意此时切换到debug模式下编译会报错:
此时请:
工程属性页->C/C++ ->命令行->键入/bigobj编译器
设置环境变量:
重启。
check
注意:务必配置好上面的几个环境变量。
打开cmd,切换到C:\local\ceres-solver-1.14.0_output\bin
路径下的Release和Debug下,然后运行分别运行helloworld.exe,如果看到convergence的话,即收敛,说明Release和Debug下的编译均成功
致谢
这个过程还是比较复杂的,我主要参考:
https://blog.csdn.net/xixihaha369300/article/details/83546473
https://www.jianshu.com/p/736e89aaf788
第一篇文章很大程度上支撑了Ceres的最后的安装步骤;第二篇则主要指导了前面部分的安装步骤。