4 Installation¶
In this section we discuss how to install and setup the MOSEK Optimizer API for C.
Important
Before running this MOSEK interface please make sure that you:
Installed MOSEK correctly. Some operating systems require extra steps. See the Installation guide for instructions and common troubleshooting tips.
Set up a license. See the Licensing guide for instructions.
Compatibility
The Optimizer API for C is compatible with the following compiler tool chains:
Platform |
Supported compiler |
Framework |
---|---|---|
Linux 64 bit x86 |
gcc (≥ 4.5) |
glibc (≥ 2.17) |
Linux 64 bit ARM |
clang (≥ 10) |
glibc (≥ 2.29) |
macOS 64 bit x86 |
Xcode (≥ 11) |
MAC OS SDK (≥ 10.15) |
macOS 64 bit ARM |
Xcode (≥ 12) |
MAC OS SDK (≥ 11) |
Windows 32 and 64 bit |
Visual Studio (≥ 2017) |
In many cases older versions can also be used.
Locating files in the MOSEK Optimization Suite
The relevant files of the Optimizer API for C are organized as reported in Table 4.1.
Relative Path |
Description |
Label |
---|---|---|
|
Header files |
|
|
Libraries and DLLs |
|
|
Examples |
|
|
Additional data |
|
where
<MSKHOME>
is the folder in which the MOSEK Optimization Suite has been installed,<PLATFORM>
is the actual platform among those supported by MOSEK, i.e.win64x86
,linux64x86
,linuxaarch64
orosxaarch64
.
Setting up the paths
To compile and link C code using the Optimizer API for C, the relevant path to the header file and library must be included, and run-time dependencies must be resolved. Hence to compile, one should add appropriate compiler and linker options. Details vary depending on the operating system and compiler. See the Makefile
included in the distribution under <MSKHOME>/mosek/11.0/tools/examples/c
for a full working example. Examples are given below.
Linux
gcc file.c -o file -I<HEADERDIR> -L<LIBDIR> -Wl,-rpath-link,<LIBDIR> -Wl,-rpath=<LIBDIR> -lmosek64
The shared library libmosek64.so.11.0
must be available at runtime.
Windows, 64bit
cl.exe /I<HEADERDIR> file.c /link /LIBPATH:<LIBDIR> /out:file.exe mosek64_11_0.lib
The shared library mosek64_11_0.dll
must be available at runtime.
macOS
clang file.c -o file -I<HEADERDIR> -L<LIBDIR> -Wl,-headerpad,128 -lmosek64 install_name_tool -change libmosek64.11.0.dylib <LIBDIR>/libmosek64.11.0.dylib file
The shared library libmosek64.11.0.dylib
must be registered and available at runtime.
4.1 Testing the Installation and Compiling Examples¶
This section describes how to verify that MOSEK has been installed correctly, and how to build and execute the C examples distributed with MOSEK.
4.1.1 Windows¶
Compiling examples using NMake
The example directory <EXDIR>
contains makefiles for use with Microsoft NMake. These makefiles requires that the Visual Studio tool chain is setup. Usually, the submenu containing Visual Studio also contains a Visual Studio Command Prompt which does the necessary setup.
To build the examples, open a DOS box and change directory to <EXDIR>
. This directory contains a makefile named Makefile
. To compile all examples, run the command
nmake /f Makefile all
To build only a single example instead of all examples, replace all
by the corresponding executable name. For example, to build lo1.exe
type
nmake /f Makefile lo1.exe
Compiling from command line
To compile and execute a distributed example, such as lo1.c
, do the following:
Compile the example into an executable
lo1.exe
(we assume that the Visual Studio C compilercl.exe
is available). For 64-bit Windows:cl <EXDIR>\lo1.c /I <HEADERDIR> /link <LIBDIR>\mosek64_11_0.lib
To run the compiled example, enter
lo1.exe
Adding MOSEK to a Visual Studio Project
The following walk-through is specific for Microsoft Visual Studio 2012, but may work for other versions too. To compile a project linking to MOSEK in Visual Studio, the following steps are necessary:
Create a project or open an existing project in Visual Studio.
In the Solution Explorer right-click on the relevant project and select Properties. This will open the Property pages dialog.
In the selection box Configuration: select All Configurations.
In the tree-view open Configuration Properties → C/C++ → General.
In the properties click the Additional Include Directories field and select edit.
Click on the New Folder button and write the full path to the
h
header file or browse for the file. For example, for 64-bit Windows use<HEADERDIR>
.Click OK.
Back in the Property Pages dialog select from the tree-view Configuration Properties → Linker → Input.
In the properties view click in the Additional Dependencies field and select edit. This will open the Additional Dependencies dialog.
Add the full path of the MOSEK
lib
. For example, for 64-bit Windows:<LIBDIR>\mosek64_11_0.lib
Click OK.
Back in the Property Pages dialog click OK.
If you have selected to link with the 64 bit version of MOSEK you must also target the 64-bit platform. To do this follow the steps below:
Open the property pages for that project.
Click Configuration Manager to open the Configuration Manager Dialog Box.
Click the Active Solution Platform list, and then select the New option to open the New Solution Platform Dialog Box.
Click the Type or select the new platform drop-down arrow, and then select the x64 platform.
Click OK. The platform you selected in the preceding step will appear under Active Solution Platform in the Configuration Manager dialog box.
4.1.2 macOS and Linux¶
The example directory <EXDIR>
contains makefiles for use with GNU Make. To build the examples enter
make -f Makefile all
To build one example instead of all examples, replace all
by the corresponding executable name. For example, to build the lo1
executable enter
make -f Makefile lo1