Joel Andersson edited this page Feb 1, 2017 · 78 revisions

Installation on LINUX

NOTE: this page is for a from-source install (useful if you want to contribute to CasADi). If you just want to evaluate CasADi quickly, use a binary install.

  • To get started quickly, start off by grabbing as many dependencies as possible from repositories.
    • Ubuntu: sudo apt-get install gcc g++ gfortran git cmake liblapack-dev pkg-config --install-recommends
    • Fedora: sudo yum install gcc gcc-c++ gcc-gfortran git cmake lapack-devel
  • To compile the Python interface, you also need SWIG and a decent Python installation:
    • Ubuntu: sudo apt-get install swig ipython python-dev python-numpy python-scipy python-matplotlib --install-recommends
    • Fedora: sudo yum install swig ipython python-devel numpy scipy python-matplotlib
  • If you want an easy-to-use Python IDE with a Matlab-like usage, we recommend you to install Spyder:
    • Ubuntu: sudo apt-get install spyder
    • Fedora: sudo yum install spyder
  • Install Third-party software that you wish to use from CasADi. Note the following:
    • The QP-solver qpOASES, the sparse direct linear solver CSparse and the integrator suite Sundials are included in CasADi and do not need to be installed separately.
    • See section on IPOPT below for installing IPOPT, including its sIPOPT extension
    • See section on WORHP below for instructions on installing WORHP.
  • Download and install CasADi from GitHub, see below.

Installing IPOPT (recommended if you plan to solve optimal control problems)

IPOPT can either be obtained from a package manager, downloaded as a binary or compiled from sources. Note that if you use the prebuilt CasADi binaries for Windows or Linux, IPOPT is included and does not need to be installed separately. You will find more information about all of these topics on the IPOPT website.

Option 1: Getting IPOPT from a package manager

On Ubuntu (or Debian) Linux and Mac OS X you can obtain IPOPT from a package manager:

  • OS X (Homebrew): brew install ipopt --with-openblas
  • Ubuntu (apt-get): sudo apt-get install coinor-libipopt-dev

Option 2: Compiling IPOPT from sources

On Linux and Mac OS X, IPOPT can be compiled from sources. You will find instructions on how to do this on their website. Our experience is that installing IPOPT is relatively easy if you follow the installation instructions on website carefully, but very hard if you try to improvise. Here is a condensed version of the installation instructions:

  • Download the latest version from SVN:
    • svn co CoinIpopt
  • Get third-party dependencies via the provided script:
    • cd CoinIpopt/ThirdParty
    • cd Blas && ./get.Blas && cd ..
    • cd Lapack && ./get.Lapack && cd ..
    • cd Metis && ./get.Metis && cd .. (Graph Coloring tool used by e.g. Mumps)
    • cd Mumps && ./get.Mumps && cd .. (Sparse direct linear solver with permissive license)
    • cd ..; mkdir build; cd build
  • Compile and install IPOPT. Compiling -fPIC often helps:
    • ../configure --prefix=/usr/local ADD_FFLAGS=-fPIC ADD_CFLAGS=-fPIC ADD_CXXFLAGS=-fPIC
    • make; sudo make install
    • If you wish to compile IPOPT with support for parametric sensitivities (sIPOPT), follow the instructions below.
  • Test if pkg-config is able to find your Ipopt installation:
    • pkg-config --libs ipopt

If this last test does not return your installed Ipopt libraries, you must set the variable PKG_CONFIG_PATH, e.g. by adding export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:<your_ipopt_pkgconfig_path> to your .bashrc or .profile file. <your_ipopt_pkgconfig_path> is the path where ipopt.pc of your Ipopt installation lives (typically <ipopt_install_dir>/lib/pkgconfig).

Option 3: Download a binary with IPOPT

On the download section of the IPOPT website you will find IPOPT compiled for a number of platforms.

Adding additional linear solvers (recommended)

To really benefit from from IPOPT, you should also try to get additional linear solvers, which can be done post-installation, regardless of how IPOPT was installed. We strongly recommend you to get at least the HSL solver MA27 (which is free). You will find instructions on that here. When filling out the forms for obtaining HSL, please mention that you plan to use the routines with Ipopt/CasADi. Unfortunately, we cannot guarantee the stability of using the newer linear solvers (MA57, MA77, MA86 and MA97 that are only free for academics) since HSL has not granted us any maintenance license.

Compiling IPOPT with support for parametric sensitivities (sIPOPT)

To compile support for parametric sensitivities in Ipopt you need to compile sIPOPT:

cd <ipopt_build_dir>/Ipopt/contrib/sIPOPT
sudo make install

The compilation of sIPOPT is known to fail if the AMPL interface was not compiled. So make sure to include the AMPL Solver Library (ASL) when compiling IPOPT.

If the sIPOPT header files are not automatically installed, you can copy them manually to your IPOPT installation:

cp <ipopt_source_dir>/Ipopt/contrib/sIPOPT/src/*.hpp <ipopt_installation_dir>/include/coin/
cp <ipopt_source_dir>/Ipopt/src/Algorithm/*.hpp <ipopt_installation_dir>/include/coin/

The reduced Hessian calculator in sIPOPT only prints out the calculated reduced Hessian to screen. If you want to be able to retrieve it, you need to download and apply the following patch to sIPOPT:

cd <ipopt_source_dir>
patch -p0 < path-to-get_reduced_hessian.patch

Installing WORHP (optional)

WORHP is a large-scale SQP method which is free for academic use. To use it point an environment variable towards your WORHP installation (e.g. by adding export WORHP=<PATH_TO_WORHP> to your .bashrc.

Installing CPLEX (optional)

IBM CPLEX is a LP/QP solver with support for discrete decision variables, free for academic use. To use it, point an environment variable towards your CPLEX installation, e.g. by adding something like the following to your .bashrc:

export PATH=/opt/ibm/ILOG/CPLEX_Studio1263/concert/include:/opt/ibm/ILOG/CPLEX_Studio1263/cplex/include:/opt/ibm/ILOG/CPLEX_Studio1263/cplex/lib/x86-64_linux/static_pic:/opt/ibm/ILOG/CPLEX_Studio1263/concert/lib/x86-64_linux/static_pic:$PATH

Building CasADi from sources

Check out CasADi from GitHub. We recommend you to check out the latest release, which is to be found in the master branch:

git clone -b master casadi

For developers, or to get the latest bug fixes, there is also the develop branch, which is where the actual development takes place. Finally, there is the tested branch which contains the latest development version that has undergone and passed nightly testing.

If you need to install a particular version of CasADi, you can do so by checking out a "release tag":

git clone casadi && cd casadi && git checkout 2.0.x

After the initial clone, you can update with:

git pull

If you are on the master branch, this will give you the latest release. If you have checked out a release tag, any updates will be backwards compatible.

Create a build directory for an out-of-source build:

cd casadi
mkdir build
cd build

Generate a makefile and build


Look at the output and make sure that CMake was able to find the software that you wanted to use together with CasADi. If a certain software was not found correctly, edit the CMakeCache.txt file which should have been generated in your build directory. Note that CasADi will only compile interfaces to software it is able to locate. To install the CasADi Python interface in a local directory, change both the PYTHON_PREFIX and CMAKE_INSTALL_PREFIX to that directory.

Important: A common problem, especially on OSX, is that the paths corresponding to your Python installation are inconsistent, especially if you have multiple Python installations on your system. Check if the fields involving PYTHON or NUMPY are consistent: linking against the or libpython2.7.dylib from one Python distribution and the Python executable from another is bound to cause problems.

Now build CasADi from source:

sudo make install

If you installed CasADi's Python front-end into a non-standard location (by setting the flag PYTHON_PREFIX, see above), make sure that the module is in your Python path, e.g. by inserting export PYTHONPATH=:${PYTHONPATH}:<python_prefix> into your .bashrc file:

The html API documentation is built as a separate target:

make doc

You may run the unit tests to see if the installation was successful:

cd .. # Go back to the main casadi source directory
cd test/python

Common problems

ImportError: /usr/lib/ undefined symbol: MPI_Init

Install libmumps-seq-4.9.2 .

/usr/include/coin/IpSmartPtr.hpp:18:4: error: #error "don't have header file for stddef"

You have a broken version of IPOPT ( 3.10.1 ), try updating. If you have installed IPOPT with a package manager, remove it and build it from sources.

In SWIG compilation: Error: Missing #endif for conditional starting on ...

You most likely have an old version of SWIG (1.3.29 or earlier). You can check the version with running swig -version in command-line. Try updating to a newer version. If you have installed SWIG with a package manager, remove it and build it from sources.

On using Ipopt: Program received signal SIGSEGV, Segmentation fault in dgemm_() Your system's version of Blas is not compatible with Ipopt. Compile coinblas, the version that Ipopt 's buildsystem provides: recompile Ipopt version after running ./get.Blas in ipopt/ThirdParty/Blas with the "--with-blas=BUILD" option.

On compiling Ipopt with "--with-blas=BUILD" option: unknown symbol sgemm, stpsv. You have obtained HSL libraries with single precision support. Ipopt is not configured to make single precision routines available in coinblas. Two options to resolve this: 1) obtain a double precision copy of ma* . ( A version where grep -i "sgemm" *.f returns nothing) 2) manually edit the in ipopt/ThirdParty/Blas: at the locations were you find dgemm.f or dgemm.lo, add the corresponding single precision symbols: sgemm.f or sgemm.lo. Repeat if other symbols are missing.

Generating Python SWIG interface fails because Python 3 is selected where casadi needs Python 2.7 (happens for e.g., Arch Linux users). Provide the four following variables in the cmake command and let them point to the appropriate Python 2.7 paths: PYTHON_EXECUTABLE, PYTHON_INCLUDE_DIR, PYTHON_LIBRARY, NUMPY_PATH. Example of custom cmake-command: cmake -DPYTHON_EXECUTABLE=/usr/bin/python2 -DPYTHON_INCLUDE_DIR=/usr/include/python2.7 -DPYTHON_LIBRARY=/usr/lib64/ -DNUMPY_PATH=/usr/include/python2.7/numpy -DWITH_PYTHON=ON ... Make sure that python 2.7 and the respective packages of numpy, scipy, matplotlib are installed on your system.