# 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 gcc (≥ 4.5) glibc (≥ 2.2)
Mac OS 64 bit Xcode (≥ 5) MAC OS SDK (≥ 10.7)
Windows 32 and 64 bit Visual Studio (≥ 2010)

In many cases older versions can also be used.

Locating Files

The files in Optimizer API for C are organized as reported in Table 1.

Table 1 Relevant files for the Optimizer API for C.
Relative Path Description Label
<MSKHOME>/mosek/8/tools/platform/<PLATFORM>/h Header files <HEADERDIR>
<MSKHOME>/mosek/8/tools/platform/<PLATFORM>/bin Libraries and DLLs <DLLDIR>, <LIBDIR>
<MSKHOME>/mosek/8/tools/examples/c Examples <EXDIR>
<MSKHOME>/mosek/8/tools/examples/data Additional data <MISCDIR>

where

• <MSKHOME> is the folder in which the MOSEK package has been installed,
• <PLATFORM> is the actual platform among those supported by MOSEK, i.e. win32x86, win64x86, linux64x86 or osx64x86.

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/8/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.8.1 must be available at runtime.

Windows, 64bit

cl.exe /I<HEADERDIR> file.c /link /LIBPATH:<LIBDIR> /out:file.exe mosek64_8_1.lib


The shared library mosek64_8_1.dll must be available at runtime.

Windows, 32bit

cl.exe /I<HEADERDIR> file.c /link /LIBPATH:<LIBDIR> /out:file.exe mosek8_1.lib


The shared library mosek8_1.dll must be available at runtime.

Mac OS

clang file.c -o file -I<HEADERDIR> -L<LIBDIR> -Wl,-headerpad,128 -lmosek64
install_name_tool -change libmosek64.8.1.dylib <LIBDIR>/libmosek64.8.1.dylib file


The shared library libmosek64.8.1.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:

1. Compile the example into an executable lo1.exe (we assume that the Visual Studio C compiler cl.exe is available). For 64-bit Windows:

cl <EXDIR>\lo1.c /I <HEADERDIR> /link <LIBDIR>\mosek64_8_1.lib

2. 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:

1. Create a project or open an existing project in Visual Studio.

2. In the Solution Explorer right-click on the relevant project and select Properties. This will open the Property pages dialog.

3. In the selection box Configuration: select All Configurations.

4. In the tree-view open Configuration PropertiesC/C++General.

5. In the properties click the Additional Include Directories field and select edit.

6. 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>.

7. Click OK.

8. Back in the Property Pages dialog select from the tree-view Configuration PropertiesLinkerInput.

9. In the properties view click in the Additional Dependencies field and select edit. This will open the Additional Dependencies dialog.

10. Add the full path of the MOSEK lib. For example, for 64-bit Windows:

<LIBDIR>\mosek64_8_1.lib

11. Click OK.

12. 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 to this follow the steps below:

1. Open the property pages for that project.
2. Click Configuration Manager to open the Configuration Manager Dialog Box.
3. Click the Active Solution Platform list, and then select the New option to open the New Solution Platform Dialog Box.
4. Click the Type or select the new platform drop-down arrow, and then select the x64 platform.
5. 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 Mac OS 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