| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415 | .. _chapter-building:============Installation============Stable Ceres Solver releases are available for download at`code.google.com <http://code.google.com/p/ceres-solver/>`_. For themore adventurous, the git repository is hosted on `Gerrit<https://ceres-solver-review.googlesource.com/>`_... _section-dependencies:Dependencies============Ceres relies on a number of open source libraries, some of which areoptional. For details on customizing the build process, see:ref:`section-customizing` .1. `CMake <http://www.cmake.org>`_ is a cross platform buildsystem. Ceres needs a relatively recent version of CMake (version2.8.0 or better).2. `eigen3 <http://eigen.tuxfamily.org/index.php?title=Main_Page>`_ isused for doing all the low level matrix and linear algebra operations.3. `google-glog <http://code.google.com/p/google-glog>`_ isused for error checking and logging. Ceres needs glog version 0.3.1 orlater. Version 0.3 (which ships with Fedora 16) has a namespace bugwhich prevents Ceres from building. Ceres contains a stripped-down,minimal version of ``glog`` called ``miniglog``, which can be enabledwith the ``MINIGLOG`` build option. If enabled, it replaces therequirement for ``glog``. However, in general it is recommended thatyou use the full ``glog``.4. `gflags <http://code.google.com/p/gflags>`_ is a library forprocessing command line flags. It is used by some of the examples andtests. While it is not strictly necessary to build the library, westrongly recommend building the library with gflags.5. `SuiteSparse<http://www.cise.ufl.edu/research/sparse/SuiteSparse/>`_ is used forsparse matrix analysis, ordering and factorization. In particularCeres uses the AMD, CAMD, COLAMD and CHOLMOD libraries. This is an optionaldependency.6. `CXSparse <http://www.cise.ufl.edu/research/sparse/CXSparse/>`_ isa sparse matrix library similar in scope to ``SuiteSparse`` but withno dependencies on ``LAPACK`` and ``BLAS``. This makes for a simplerbuild process and a smaller binary.  The simplicity comes at a cost --for all but the most trivial matrices, ``SuiteSparse`` issignificantly faster than ``CXSparse``. This is an optional dependency.7. `BLAS <http://www.netlib.org/blas/>`_ and `LAPACK<http://www.netlib.org/lapack/>`_ routines are needed bySuiteSparse, and optionally used by Ceres directly for some operations.We recommend `ATLAS <http://math-atlas.sourceforge.net/>`_,which includes BLAS and LAPACK routines. It is also possible to use`OpenBLAS <https://github.com/xianyi/OpenBLAS>`_ . However, one needsto be careful to `turn off the threading<https://github.com/xianyi/OpenBLAS/wiki/faq#wiki-multi-threaded>`_inside ``OpenBLAS`` as it conflicts with use of threads in Ceres... _section-linux:Building on Linux=================We will use `Ubuntu <http://www.ubuntu.com>`_ as our exampleplatform. Start by installing all the dependencies... NOTE:: Up to at least Ubuntu 13.10, the SuiteSparse package in the official package repository (built from SuiteSparse v3.4.0) **cannot** be used to build Ceres as a *shared* library.  Thus if you want to build Ceres as a shared library using SuiteSparse, you must perform a source install of SuiteSparse.  It is recommended that you use the current version of SuiteSparse (4.2.1 at the time of writing)... code-block:: bash     # CMake     sudo apt-get install cmake     # gflags     tar -xvzf gflags-2.0.tar.gz     cd gflags-2.0     ./configure --prefix=/usr/local     make     sudo make install.     # google-glog must be configured to use the previously installed gflags     tar -xvzf glog-0.3.2.tar.gz     cd glog-0.3.2     ./configure --with-gflags=/usr/local/     make     sudo make install     # 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     #   perform a source install of SuiteSparse (and uninstall the Ubuntu     #   package if it is currently installed.We are now ready to build and test Ceres... code-block:: bash tar zxf ceres-solver-1.7.0.tar.gz mkdir ceres-bin cd ceres-bin cmake ../ceres-solver-1.7.0 make -j3 make testYou can also try running the command line bundling application with one of theincluded problems, which comes from the University of Washington's BALdataset [Agarwal]_... code-block:: bash bin/simple_bundle_adjuster ../ceres-solver-1.7.0/data/problem-16-22106-pre.txtThis runs Ceres for a maximum of 10 iterations using the``DENSE_SCHUR`` linear solver. The output should look something likethis... code-block:: bash    0: f: 4.185660e+06 d: 0.00e+00 g: 1.09e+08 h: 0.00e+00 rho: 0.00e+00 mu: 1.00e+04 li:  0 it: 1.16e-01 tt: 3.39e-01    1: f: 1.062590e+05 d: 4.08e+06 g: 8.99e+06 h: 5.36e+02 rho: 9.82e-01 mu: 3.00e+04 li:  1 it: 3.90e-01 tt: 7.29e-01    2: f: 4.992817e+04 d: 5.63e+04 g: 8.32e+06 h: 3.19e+02 rho: 6.52e-01 mu: 3.09e+04 li:  1 it: 3.52e-01 tt: 1.08e+00    3: f: 1.899774e+04 d: 3.09e+04 g: 1.60e+06 h: 1.24e+02 rho: 9.77e-01 mu: 9.26e+04 li:  1 it: 3.60e-01 tt: 1.44e+00    4: f: 1.808729e+04 d: 9.10e+02 g: 3.97e+05 h: 6.39e+01 rho: 9.51e-01 mu: 2.78e+05 li:  1 it: 3.62e-01 tt: 1.80e+00    5: f: 1.803399e+04 d: 5.33e+01 g: 1.48e+04 h: 1.23e+01 rho: 9.99e-01 mu: 8.33e+05 li:  1 it: 3.54e-01 tt: 2.16e+00    6: f: 1.803390e+04 d: 9.02e-02 g: 6.35e+01 h: 8.00e-01 rho: 1.00e+00 mu: 2.50e+06 li:  1 it: 3.59e-01 tt: 2.52e+00 Ceres Solver Report -------------------                                      Original                  Reduced Parameter blocks                        22122                    22122 Parameters                              66462                    66462 Residual blocks                         83718                    83718 Residual                               167436                   167436 Trust Region Strategy     LEVENBERG_MARQUARDT                                         Given                     Used Linear solver                     DENSE_SCHUR              DENSE_SCHUR Preconditioner                            N/A                      N/A Threads:                                    1                        1 Linear solver threads                       1                        1 Linear solver ordering              AUTOMATIC                 22106,16 Cost: Initial                          4.185660e+06 Final                            1.803390e+04 Change                           4.167626e+06 Number of iterations: Successful                                  6 Unsuccessful                                0 Total                                       6 Time (in seconds): Preprocessor                        2.229e-01   Evaluator::Residuals              7.438e-02   Evaluator::Jacobians              6.790e-01   Linear Solver                     1.681e+00 Minimizer                           2.547e+00 Postprocessor                       1.920e-02 Total                               2.823e+00 Termination:               FUNCTION_TOLERANCE.. section-osx:Building on Mac OS X====================On OS X, we recommend using the `homebrew<http://mxcl.github.com/homebrew/>`_ package manager to install thedependencies. There is no need to install ``BLAS`` or ``LAPACK``separately as OS X ships with optimized ``BLAS`` and ``LAPACK``routines as part of the `vecLib<https://developer.apple.com/library/mac/#documentation/Performance/Conceptual/vecLib/Reference/reference.html>`_framework... code-block:: bash      # CMake      brew install cmake      # google-glog and gflags      brew install glog      # Eigen3      brew install eigen      # SuiteSparse and CXSparse      brew install suite-sparseWe are now ready to build and test Ceres... code-block:: bash   tar zxf ceres-solver-1.7.0.tar.gz   mkdir ceres-bin   cd ceres-bin   cmake ../ceres-solver-1.7.0   make -j3   make testLike the Linux build, you should now be able to run``bin/simple_bundle_adjuster``... _section-windows:Building on Windows with Visual Studio======================================On Windows, we support building with Visual Studio 2010 or newer. Notethat the Windows port is less featureful and less tested than theLinux or Mac OS X versions due to the unavailability of SuiteSparseand ``CXSparse``. Building is also more involved since there is noautomated way to install the dependencies.#. Make a toplevel directory for deps & build & src somewhere: ``ceres/``#. Get dependencies; unpack them as subdirectories in ``ceres/``   (``ceres/eigen``, ``ceres/glog``, etc)   #. ``Eigen`` 3.1 (needed on Windows; 3.0.x will not work). There is      no need to build anything; just unpack the source tarball.   #. ``google-glog`` Open up the Visual Studio solution and build it.   #. ``gflags`` Open up the Visual Studio solution and build it.#. Unpack the Ceres tarball into ``ceres``. For the tarball, you   should get a directory inside ``ceres`` similar to   ``ceres-solver-1.3.0``. Alternately, checkout Ceres via ``git`` to   get ``ceres-solver.git`` inside ``ceres``.#. Install ``CMake``,#. Make a dir ``ceres/ceres-bin`` (for an out-of-tree build)#. Run ``CMake``; select the ``ceres-solver-X.Y.Z`` or   ``ceres-solver.git`` directory for the CMake file. Then select the   ``ceres-bin`` for the build dir.#. Try running ``Configure``. It won't work. It'll show a bunch of options.   You'll need to set:   #. ``GLOG_INCLUDE``   #. ``GLOG_LIB``   #. ``GFLAGS_LIB``   #. ``GFLAGS_INCLUDE``   to the appropriate place where you unpacked/built them.#. You may have to tweak some more settings to generate a MSVC   project.  After each adjustment, try pressing Configure & Generate   until it generates successfully.#. Open the solution and build it in MSVCTo run the tests, select the ``RUN_TESTS`` target and hit **BuildRUN_TESTS** from the build menu.Like the Linux build, you should now be able to run``bin/simple_bundle_adjuster``.Notes:#. The default build is Debug; consider switching it to release mode.#. Currently ``system_test`` is not working properly.#. Building Ceres as a DLL is not supported; patches welcome.#. CMake puts the resulting test binaries in ``ceres-bin/examples/Debug``   by default.#. The solvers supported on Windows are ``DENSE_QR``, ``DENSE_SCHUR``,   ``CGNR``, and ``ITERATIVE_SCHUR``.#. We're looking for someone to work with upstream ``SuiteSparse`` to   port their build system to something sane like ``CMake``, and get a   supported Windows port... _section-android:Building on Android===================Download the ``Android NDK``. Run ``ndk-build`` from inside the``jni`` directory. Use the ``libceres.a`` that gets created... _section-customizing:Customizing the build=====================It is possible to reduce the libraries needed to build Ceres andcustomize the build process by setting the appropriate options in``CMake``.  These options can either be set in the ``CMake`` GUI,or via ``-D<OPTION>=<ON/OFF>`` when running ``CMake`` from thecommand line.  In general, you should only modify these options fromtheir defaults if you know what you are doing.#. ``LAPACK [Default: ON]``: By default Ceres will use ``LAPACK`` (&   ``BLAS``) if they are found.  Turn this ``OFF`` to build Ceres   without ``LAPACK``. Turning this ``OFF`` also disables   ``SUITESPARSE`` as it depends on ``LAPACK``.#. ``SUITESPARSE [Default: ON]``: By default, Ceres will link to   ``SuiteSparse`` if it and all of its dependencies are present. Turn   this ``OFF`` to build Ceres without ``SuiteSparse``. Note that   ``LAPACK`` must be ``ON`` in order to build with ``SuiteSparse``.#. ``CXSPARSE [Default: ON]``: By default, Ceres will link to   ``CXSparse`` if all its dependencies are present. Turn this ``OFF``   to build Ceres without ``CXSparse``.#. ``GFLAGS [Default: ON]``: Turn this ``OFF`` to build Ceres without   ``gflags``. This will also prevent some of the example code from   building.#. ``MINIGLOG [Default: OFF]``: Ceres includes a stripped-down,   minimal implementation of ``glog`` which can optionally be used as   a substitute for ``glog``, thus removing ``glog`` as a required   dependency. Turn this ``ON`` to use this minimal ``glog``   implementation.#. ``SCHUR_SPECIALIZATIONS [Default: ON]``: If you are concerned about   binary size/compilation time over some small (10-20%) performance   gains in the ``SPARSE_SCHUR`` solver, you can disable some of the   template specializations by turning this ``OFF``.#. ``LINE_SEARCH_MINIMIZER [Default: OFF]``: The line search based   minimizer is mostly suitable for large scale optimization problems,   or when sparse linear algebra libraries are not available. You can   further save on some compile time and binary size by turning this   ``OFF``.#. ``OPENMP [Default: ON]``: On certain platforms like Android,   multi-threading with ``OpenMP`` is not supported. Turn this ``OFF``   to disable multithreading.#. ``BUILD_SHARED_LIBS [Default: OFF]``: By default Ceres is built as   a static library, turn this ``ON`` to instead build Ceres as a   shared library.#. ``BUILD_DOCUMENTATION [Default: OFF]``: Use this to enable building   the documentation, requires `Sphinx <http://sphinx-doc.org/>`_. In   addition, ``make ceres_docs`` can be used to build only the   documentation... _section-using-ceres:Using Ceres with CMake======================Once the library is installed with ``make install``, it is possible touse CMake with `FIND_PACKAGE()<http://www.cmake.org/cmake/help/v2.8.10/cmake.html#command:find_package>`_in order to compile **user code** against Ceres. For example, for`examples/helloworld.cc<https://ceres-solver.googlesource.com/ceres-solver/+/master/examples/helloworld.cc>`_the following CMakeList.txt can be used:.. code-block:: cmake    CMAKE_MINIMUM_REQUIRED(VERSION 2.8)    PROJECT(helloworld)    FIND_PACKAGE(Ceres REQUIRED)    INCLUDE_DIRECTORIES(${CERES_INCLUDES})    # helloworld    ADD_EXECUTABLE(helloworld helloworld.cc)    TARGET_LINK_LIBRARIES(helloworld ${CERES_LIBRARIES})Specify Ceres version---------------------Additionally, when CMake has found Ceres it can check the packageversion, if it has been specified in the `FIND_PACKAGE()<http://www.cmake.org/cmake/help/v2.8.10/cmake.html#command:find_package>`_call.  For example:.. code-block:: cmake    FIND_PACKAGE(Ceres 1.2.3 REQUIRED)The version is an optional argument.Local installations-------------------If Ceres was installed in a non-standard path by specifying-DCMAKE_INSTALL_PREFIX="/some/where/local", then the user should addthe **PATHS** option to the ``FIND_PACKAGE()`` command. e.g.,.. code-block:: cmake   FIND_PACKAGE(Ceres REQUIRED PATHS "/some/where/local/")Note that this can be used to have multiple versions of Ceresinstalled.
 |