The Google Ceres Solver is a nonlinear least-squares solver. It’s an efficient library that can be used to solve nonlinear least-squares problems like fitting a cone, sphere or cylinder to a set of 3-dimensional points. If you want some good non-linear least-squares fit equations to use for the solver, you might want to take a look at this. Building the Ceres Solver on Windows, especially x64 Windows, is not a trivial task. Here we give the details necessary for building it from source and also provide 64-bit binaries for your convenience for Ceres Solver version 1.3.0. These instructions were created for the latest versions of the libraries available at the time of its writing. Newer libraries might require changes. These instructions are also specifically for Visual Studio but could be adapted to other compilers. Many of the steps below require a file extraction tool. Our favorite tool for Windows is 7-zip since it’s open source and handles most formats.
Building From Source
- Download Ceres Solver source (tar.gz file) from here.
- Download latest CMake binary (Windows 32-bit Installer) from here.
- Download the stable release of Eigen3 from here (tar.bz2, tar.gz or zip will all work).
- Download the latest google-glog logging library from here.
- Download the latest gflags commandline flags library from here (both tar.gz and zip will work).
- Make a toplevel directory for the dependencies, source and build files somewhere. Here we will assume you called it ceres.
- Unpack Ceres Solver into the ceres directory. You should get a directory in ceres such as ceres-solver-1.3.0.
- Unpack Eigen3 into ceres/eigen, google-glog into ceres/glog and gflags into ceres/gflags.
- Go into ceres/glog. Open src/windows/glog/logging.h and change from:
C++123#if 0#include <gflags/gflags.h>#endif
123#if 1#include <gflags/gflags.h>#endif
Open src/windows/glog/config.h and change #undef HAVE_LIB_GFLAGS to #define HAVE_LIB_GFLAGS.
Open src/logging.cc and comment out the line _asm int 3 in the logging_fail static method.
- Load the project file in Visual Studio and build it. If desired (which it was for us) you may also want to build a debug version. By default it’s given the same name as the release. So go into the project’s Settings, General, Target Name and change it to end with a “_d” or whatever you’d like.
- Go into ceres/gflags, load the project file in Visual Studio and build it. If you want a debug version, follow the instructions in the previous step. However, you’ll also want to include the debug version of glog here so modify the project’s Settings, Linker, Inputs to reference the debug library built in the previous step.
- Make a directory ceres/ceres-bin for the build files.
- Run CMake and select the ceres-solver-X.Y.Z directory for the CMake file. Then select ceres-bin for the build directory.
- Run ‘Configure’. It will return errors for options that need to be filled in.
- Set GLOG_INCLUDE to the full path to ceres/gflags/src/windows.
- Set GLOG_LIB to the full path to ceres/gflags/Release/libgflags.lib.
- Set GFLAGS_LIB to the full path to ceres/glog/src/windows.
- Set GFLAGS_INCLUDE to ceres/glog/Release/libglog.lib.
- Open the solution in Visual Studio. Make the same changes here as described in step 10 above if you’d like a debug version built and make sure to reference the correct debug library names you created for glog and gflags in the projects that need them. Then build the solution which will put the resulting library files into ceres/ceres-bin/lib.
- In your own tool, you’ll have to add #define GLOG_NO_ABBREVIATED_SEVERITIES before including ceres.