Windows下编译ceres2.0.0的库文件
Android和Windows都编译成功
本人使用的是2.0.0版本,编译成功,测试可用
自己编写的Android需要的jni文件下载链接
https://download.csdn.net/download/qq_35947425/15841937
自己编译的ceres2.0.0库Android和Windows,下载链接
https://download.csdn.net/download/qq_35947425/15842442
编译前准备
- ceres-solver-2.0.0
ceres最新链接 - Eigen 3.3 or later required.
- CMake 3.5 or later required.
- AndroidNDK 我使用的是AndroidStudioSdk中的Sdk\ndk\21.3.6528147版本的ndk-build,使用高版本23.0.7123448编译不通过,对应的你们可以下载使用21版本
- VisualStudio
windows库
-
安装cmake之后配置安装目录下bin文件夹到环境变量Path中
-
cmake编译Eigen
在Eigen中创建Build文件夹,在文件夹中打开cmd窗口运行cmake ..
,等待编译完成即可,看见生成Eigen3Config.cmake和Eigen3Targets.cmake即可 -
在ceres源码目录创建Build文件夹
-
打开cmake.exe界面
然后点Configure,此时会报错或者什么,修改编译配置
然后再点击Configure,Generate此时会生成vs的工程
打开vs工程然后编译生成ceres.lib即可,可运行测试工程测试 -
然后新建文件夹CeresLib文件夹,然后新建lib和include文件夹
-
拷贝lib文件到lib文件夹
-
拷贝头文件相关到include文件夹中
- ceres-solver-2.0.0\include下的ceres文件夹到include
- ceres-solver-2.0.0\internal下的ceres文件夹到include(文件夹中的.h即可)
- ceres-solver-2.0.0\Build\config下的ceres文件夹到include
- ceres-solver-2.0.0\internal\ceres\miniglog下的glog文件夹到include
此时include文件夹下有ceres文件夹和glog文件夹,只需配置一个include即可
-
同时包含Eigen源码文件夹
Android库
-
解压AndroidNDK之后,配置bin目录到环境变量Path
-
下载我编写好的jni文件夹,将jni文件夹放到源码目录下
-
修改jni目录下mk文件
-
打开Android.mk 修改
- 85行 EIGEN_PATH := (你的Eigen源码文件夹)\Eigen
- 109行宏定义配置(如果需要和你编译的windows配置一样,打开windows下编译的目录Build\config\ceres\internal\config.h,按你定义的配置宏即可)
或者不修改直接编译 - 126行 LOCAL_SRC_FILES 对照你的版本查看.cc文件是否包含完整,不包括xxtest.cc测试文件
配置宏说明
// If defined, use the LGPL code in Eigen.
#define CERES_USE_EIGEN_SPARSE
// If defined, Ceres was compiled without LAPACK.
#define CERES_NO_LAPACK
// If defined, Ceres was compiled without SuiteSparse.
#define CERES_NO_SUITESPARSE
// If defined, Ceres was compiled without CXSparse.
#define CERES_NO_CXSPARSE
// If defined, Ceres was compiled without Apple's Accelerate framework solvers.
#define CERES_NO_ACCELERATE_SPARSE
#if defined(CERES_NO_SUITESPARSE) && \
defined(CERES_NO_ACCELERATE_SPARSE) && \
defined(CERES_NO_CXSPARSE) && \
!defined(CERES_USE_EIGEN_SPARSE) // NOLINT
// If defined Ceres was compiled without any sparse linear algebra support.
#define CERES_NO_SPARSE
#endif
// If defined, Ceres was compiled without Schur specializations.
#define CERES_RESTRICT_SCHUR_SPECIALIZATION
// If defined, Ceres was compiled to use Eigen instead of hardcoded BLAS
// routines.
#define CERES_NO_CUSTOM_BLAS
// If defined, Ceres was compiled without multithreading support.
#define CERES_NO_THREADS
// If defined Ceres was compiled with OpenMP multithreading.
#define CERES_USE_OPENMP
// If defined Ceres was compiled with modern C++ multithreading.
#define CERES_USE_CXX_THREADS
// If defined, Ceres was built as a shared library.
#define CERES_USING_SHARED_LIBRARY
// If defined, Ceres was compiled with a version MSVC >= 2005 which
// deprecated the standard POSIX names for bessel functions, replacing them
// with underscore prefixed versions (e.g. j0() -> _j0()).
#define CERES_MSVC_USE_UNDERSCORE_PREFIXED_BESSEL_FUNCTIONS
- 修改Application.mk文件
不需要修改 只能用c++14编译 低版本c++11有些不支持 - 然后再源码目录下打开cmd窗口运行ndk-build 等待编译完成即可
- 然后新建文件夹CeresLib文件夹,然后新建lib和include文件夹
- 拷贝.a文件到lib文件夹
- 拷贝头文件相关到include文件夹中
- ceres-solver-2.0.0\include下的ceres文件夹到include
- ceres-solver-2.0.0\internal下的ceres文件夹到include(文件夹中的.h即可)
- 复制ceres-solver-2.0.0\config\ceres\internal\config.h文件到include\ceres\internal、文件夹下,同时添加Android.mk 109行宏定义在此文件中(windows和Android配置不一样,注意修改)
- ceres-solver-2.0.0\internal\ceres\miniglog下的glog文件夹到include.
此时include文件夹下有ceres文件夹和glog文件夹,只需配置一个include即可
同时包含Eigen源码文件夹