Build from sources
Install GCC and CMake
The main compilation directives are specified using
GCC compiler to build the binaries
CMake to create the Makefiles
Linux
Both gcc
and cmake
commands are already installed by default.
Mac OS
Install Xcode and command line tools
Install the latest release of Xcode.
Install the command line tools by executing from the terminal
xcode-select --install
Install CMake via Homebrew
Install Homebrew and update its packages to the latest version.
Install cmake by executing
brew install cmake
Windows
Build the binaries
Run the following commands from the terminal
You first need to get the sources from one of these two options:
Download the compressed source file from the latest OSQP release at GitHub.
Clone the repository
git clone https://github.com/osqp/osqp
Create
build
directory and change directorycd osqp mkdir build cd build
Create Makefiles
In Linux and Mac OS run
cmake -G "Unix Makefiles" ..
In Windows run
cmake -G "MinGW Makefiles" ..
Compile OSQP
cmake --build .
Thanks to CMake, it is possible to create projects for a wide variety of IDEs; see here for more details. For example, to create a project for Visual Studio 17 2022, it is just necessary to run
cmake -G "Visual Studio 17 2022" ..
To generate unittests for OSQP, specify the -DOSQP_BUILD_UNITTESTS=ON flag. This requires that you have numpy and scipy python modules, so it is best to do this in a python virtual environment where you have these packages installed.
cmake -G "Unix Makefiles" -DOSQP_BUILD_UNITTESTS=ON ..
The compilation will generate the demo osqp_demo
(and the unittests osqp_tester
if you generated them) executable. In the case of Unix Makefiles
or MinGW Makefiles
option they are located in the build/out/
directory. Run them to check that the compilation was correct.
Once the sources are built, the generated static build/out/libosqpstatic.a
and shared build/out/libosqp.ext
(where ext
is .so/.dylib/.dll
depending on your platform) libraries can be used to interface any C/C++ software to OSQP (see C installation).
Install the binaries
To install the generated libraries and headers to a system-wide location compatible with GNU standards it is just necessary to run
cmake --build . --target install
This code installs the libraries in libdir
and the headers into includedir/osqp
. For mode details see the defaults folders on the GNU standards website.
To change the installation prefix, in the “Create Makefiles” step above, you need to specify the destination folder as cmake -DCMAKE_INSTALL_PREFIX:PATH=myfolder ..
.
Note
This step requires write permissions in the destination
folders. You might be able to gain access using the
sudo
command.
We provided also an uninstall routine to remove the copied files by running
cmake --build . --target uninstall
Note that this corresponds to running make install
and make uninstall
on unix machines.