This page contains detailed instructions for building and installing all of alpaqa from scratch. For the installation of the Python package without building it from source, please see these instructions.
First, install some basic tools: C and C++ compilers, Git, and Python (you'll need the development version to build alpaqa's Python interface, and we install the venv
module to create virtual environments).
The alpaqa package requires a relatively recent compiler (tested using GCC 10-13, Clang 14-16).
To install GCC 11 on older versions of Ubuntu, you can use
To install the latest version of Clang, you can use the instructions from https://apt.llvm.org:
For convenience, we'll install everything into a Python virtual environment (including the C++ libraries and dependencies). This allows you to easily experiment in a sandbox, without requiring root permissions, and without the risk of messing with system packages.
The scripts
folder contains some Bash scripts to install the necessary dependencies. Feel free to inspect and modify the installation scripts. If you already have the dependencies installed globally you can skip these steps.
CasADi is built as a static library because it is later statically linked into the final alpaqa libraries for better portability, this is especially useful when creating the Python package. If you need to link against CasADi dynamically, you can use the install-casadi.sh
script instead.
The following commands build and install the alpaqa C++ library into the virtual environment.
You may want to change the installation prefix, e.g. use --prefix /usr/local
for a system-wide install (requires sudo
), or --prefix $HOME/.local
to install it for the current user.
Installing both the release and debug versions can be very useful for checking matrix dimension errors and out of bounds accesses during development, and switching to an optimized version later.
Note
If you changed the installation prefix, and unless you installed the package to a system folder like/usr/local
, you'll have to add~/.local
to theCMAKE_PREFIX_PATH
, e.g. by adding the following to your~/.profile
file, where$HOME/.local
was the prefix used in the when installing alpaqa earlier:export CMAKE_PREFIX_PATH="$HOME/.local:$CMAKE_PREFIX_PATH"Then source it (
. ~/.profile
) or log out and back in again.
The instructions for Windows are quite similar to the ones for Linux. To install the dependencies, you can use the Powershell scripts instead of the Bash scripts:
The instructions for macOS are the same as the ones for Linux, with the caveat that the default AppleClang compiler might not yet support the necessary C++20 features used by alpaqa. If this is the case, you can use a mainline Clang compiler (version 16 or higher), that you install using Homebrew or another package manager.
You can select the compiler to use by setting the CC
and CXX
environment variables and reconfiguring the project, for example:
If your Clang installation is older than version 16, you'll have to disable the optional OCP component, by using the -D ALPAQA_WITH_OCP=Off
CMake option. This should work for Clang 14 and later.
Once the library is installed, you can use it in your own projects.
For example:
main.cpp
CMakeLists.txt
After creating the virtual environment and installing the dependencies, you can install the Python module using:
To build the Python package without installing, you can use: