Skip to content
Joel Andersson edited this page Oct 13, 2023 · 91 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 22.04: sudo apt 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 a decent Python installation (omit this if you already have a Python installation):
  • Ubuntu 22.04: sudo apt install ipython3 python3-dev python3-numpy python3-scipy python3-matplotlib --install-recommends
  • Fedora: sudo yum install ipython python-devel numpy scipy python-matplotlib
  • To compile the Python interface, you also need SWIG:
  • Ubuntu 22.04: sudo apt install swig --install-recommends
  • Fedora: sudo yum install swig Note that using mainline SWIG only works for the Python interface - for the MATLAB/Octave interfaces we need to use our fork of SWIG, cf. the Matlab page.
  • If you don't already have a good editor/IDE, we recommend you to install Visual Studio Code following its installation instructions.
  • Third-party dependencies for CasADi can either be installed separately, prior to CasADi installation, or be downloaded and installed automatically by the CasADi installer.
  • Download and install CasADi from GitHub, see below.

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 main branch:

git clone https://github.com/casadi/casadi.git -b main 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 https://github.com/casadi/casadi.git 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

cmake -DWITH_PYTHON=ON -DWITH_PYTHON3=ON ..

If you installed IPOPT, you should also include the flag -DWITH_IPOPT=ON

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 libpython2.7.so or libpython2.7.dylib from one Python distribution and the Python executable from another is bound to cause problems.

Now build CasADi from source:

make
sudo make install

The html API documentation is built as a separate target:

make doc

Running casadi from python

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:

Run unittest

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
python alltests.py

User installation and Python virtualenv

If you want to compile and install casadi to local path, without interfering with eventual system installation, without using sudo, i.e. for developing purposes, you can run for example the following command:

cd build
cmake -DWITH_PYTHON=ON -DPYTHON_PREFIX=../lib -DCMAKE_INSTALL_PREFIX=../lib  ..

make -j$(nproc) install

This will place the compiled library and the Python module in the local ./lib.

If you are using a python virtualenv you can create a file called easy-install.pth in the following path:

<virtualenv-folder>/lib/<python-version>/site-packages/

inside the file you should add a line with the path of the casadi python module generated by cmake, using the command about the path would be <casadi-repo>/lib once activated the virtualenv a portable oneliner would be:

cd .. # go back to casadi repo main directory
echo "$(pwd)/lib" >> $(python -c 'import site, os; print(os.path.join(site.getsitepackages()[0],"easy-install.pth"))')

This will create a link between the compiled python module and the virtualenv in this way every time cmake invoked a new version of casadi would be available through the virtualenv.

Common problems

ImportError: /usr/lib/libipopt.so.0: 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 Makefile.in 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.

Clone this wiki locally