C / C++¶
First clone the SCS repo from GitHub
git clone https://github.com/cvxgrp/scs.git
CMake¶
Thanks to the CMake buildsystem (contributed by Giulio Romualdi), SCS can be easily compiled and linked to other CMake projects. To use the cmake buld system please run the following commands:
cd scs
mkdir build
cd build
cmake -DCMAKE_INSTALL_PREFIX:PATH=<custom-folder> ../
make
make install
You may also want to compile the tests. In this case when you configure the project, please call the following command
cmake -DCMAKE_INSTALL_PREFIX:PATH=<custom-folder> -DBUILD_TESTING=ON ../
make
ctest
By default the build-system will compile the library as shared. If you want to compile it as static, please call the following command when you configure the project
cmake -DCMAKE_INSTALL_PREFIX:PATH=<custom-folder> -BUILD_SHARED_LIBS=OFF ../
make
The CMake build-system exports two CMake targets called scs::scsdir
and
scs::scsindir
which can be imported using the find_package CMake command and
used by calling target_link_libraries as in the following example:
cmake_minimum_required(VERSION 3.0)
project(myproject)
find_package(scs REQUIRED)
add_executable(example example.cpp)
# To use the direct method
target_link_libraries(example scs::scsdir)
# To use the indirect method
target_link_libraries(example scs::scsindir)
Makefile¶
Alternatively you can use the Makefile and manage the libraries yourself
cd scs
make
To compile and run the tests execute
make test
out/run_tests_direct
out/run_tests_indirect
If make completes successfully, it will produce two static library files,
libscsdir.a
, libscsindir.a
, and two dynamic library files
libscsdir.ext
, libscsindir.ext
(where .ext
extension is
platform dependent) in the out
folder.
If you have a GPU and have CUDA installed, you can also execute make gpu to
compile SCS to run on the GPU which will create additional libraries and demo
binaries in the out folder corresponding to the GPU version. Note that the GPU
(usually) requires 32 bit ints, which can be enforced by compiling with
DLONG=0
.
make gpu DLONG=0
out/run_tests_gpu_indirect
To use the libraries in your own source code, compile your code with the linker
option -L(PATH_TO_SCS_LIBS)
and -lscsdir
or -lscsindir
(as needed). The API and required data structures are defined in the file
include/scs.h
. The four main API functions are: