This chapter describes how to verify that MOSEK has been installed and set up correctly, and how to compile, link and execute a C example distributed with MOSEK.
Usage of the MOSEK C API requires a working installation of MOSEK and the installation of a valid license file — see the MOSEK Installation Manual for instructions.
If MOSEK is installed correctly, you should be able to execute the MOSEK command line tool.
If MOSEK was installed using the automatic installer, the default location is
C:\Program Files\mosek\6\
unless a different path was specified.
To check that MOSEK is installed correctly, please do the following.
Enter
mosek.exe -f
This will execute the MOSEK command line tool and print some relevant information. For example:
MOSEK Version 6.0.0.29(beta) (Build date: 2009-7-28 17:28:26) Copyright (c) 1998-2009 MOSEK ApS, Denmark. WWW: http://www.mosek.com Global optimizer version: 6.0.1.282. Global optimizer build date: Jul 20 2009 15:24:58 Barrier Solver Version 6.0.0.029, Platform Windows x64. 64 bit architecture. Using FLEXlm version: 11.6. Hostname: 'morud' Hostid: '"0015c5f32f32 0015c5f32f30"' Operating system variables MOSEKLM_LICENSE_FILE : PATH : c:\local\python24;c:\local\bin;C:\Program Files\mosek\6\tools\platform\win64x86\bin *** Warning: No input file specified. Common usage of the MOSEK command line tool is: mosek file_name Return code - 0 [MSK_RES_OK]
Verify that
There is no automatic installer for MOSEK on Linux, thus installation is performed manually: See MOSEK Installation Manual for details.
To check that MOSEK is installed correctly, please do the following:
Enter
mosek -f
This will execute the MOSEK command line tool and print some relevant information. For example:
MOSEK Version 5.0.0.3(alpha) (Build date: Nov 23 2006 10:56:35) Copyright (c) 1998-2006 MOSEK ApS, Denmark. WWW: http://www.mosek.com Global optimizer version: 4.50.343. Global optimizer build date: Nov 10 2006 08:37:51. Using FLEXlm version: 11.3. Hostname: 'kolding' Hostid: '00001a1a5a6a' Operating system variables MOSEKLM_LICENSE_FILE : /home/ulfw/mosek/5/licenses LD_LIBRARY_PATH : /home/ulfw/mosek/5/tools/platform/win/bin:/home/ulfw/lib *** Warning: No input file specified. Common usage of the MOSEK command line tool is: mosek file_name Return code - 0 [MSK_RES_OK]
Verify that
There is no automatic installer for MOSEK on Linux. Installation is performed manually: See MOSEK Installation Manual for details.
To check that MOSEK is correctly installed, go though the following steps.
Enter
mosek -f
This will execute the MOSEK command line tool and print some relevant information.
Verify that
This section demonstrates how to compile, link and run the example lo1.c included with MOSEK. The general requirements for a program linking to the MOSEK library are the same as for lo1.c.
It is assumed that MOSEKis installed, and that there is a working C compiler on the system.
We assume that MOSEK is installed under the default path
c:\Program Files\mosek\6
and that the platform-specific files are located in
c:\Program Files\mosek\6\tools\platform\<platform>\
where <platform> is win (32-bit Windows), win64x86 (64-bit Windows AMD64 or Intel64) or winia64 (Windows Itanium).
The example directory contains makefiles for use with Microsoft NMake. This requires that paths and environment are set up for the Visual Studio tool chain (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 the examples directory. For Windows with default installation directories, the example directory is
c:\Program Files\mosek\6\tools\examples\c
The directory contains a makefile named “Makefile”. To compile all examples, run the command
nmake /f Makefile all
To only build 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
To compile and run a C example using the MOSEK dll, the following files are required:
mosek.h. The header file defining all functions and constants in MOSEK
c:\Program Files\mosek\6\tools\platform\<platform>\h\mosek.h
The MOSEK lib file located in
c:\Program Files\mosek\6\tools\platform\<platform>\dll
The relevant lib file is
on 64-bit Microsoft Windows (AMD x64 or Intel EMT64)
mosek64_6_0.lib
on 32-bit Microsoft Windows
mosek6_0.lib
The MOSEK solver dll located in
c:\Program Files\mosek\6\tools\platform\<platform>\bin
The relevant dll file is
on 64-bit Microsoft Windows (AMD x64 or Intel EMT64)
mosek64_6_0.dll
on 32-bit Microsoft Windows
mosek6_0.dll
Finally, the distributed C examples are located in the directory
c:\Program Files\mosek\6\tools\examples\c
To compile and execute the distributed example lo1.c, do the following:
Change directory:
c: cd "\Program Files\mosek\6\tools"
Compile the example into an executable lo1.exe (we assume that the Visual Studio C compiler cl.exe is available). For Windows 32
cl examples\c\lo1.c /out:lo1.exe /I platform\win32x86\h\mosek.h platform\win32x86\bin\mosek6_0.lib
For Windows 64:
cl examples\c\lo1.c /out:lo1.exe /I platform\win64x86\h\mosek.h platform\win64x86\bin\mosek64_6_0.lib
To run the compiled examples, enter
./lo1.exe
The following walk-through is specific for Microsoft Visual Studio 7 (.NET), but may work for other versions too.
To compile a project linking to MOSEK in Visual Studio, the following steps are necessary:
Click on the New Folder button and write the full path to the mosek.h header file or browse for the file by clicking the ellipsis “...”. For example, for 32-bit Windows enter
C:\Program Files\mosek\6\tools\platform\win32x86\h
In the text field enter the full path of the MOSEK lib on a new line. For example, for 32-bit Windows
C:\Program Files\mosek\6\tools\platform\win32x86\bin\mosek6_0.lib
Additionally, if you want to add the mosek.h header file to your project, do the following:
The mosek.h header file which must be included in all files that uses MOSEK functions is located in the directory
mosek/6/tools/platform/<platform>/h/mosek.h
and the MOSEK shared (or dynamic) library is located in
mosek/6/tools/platform/<platform>/bin/libmosek64.so.6.0
for 64-bit architectures, and in
mosek/6/tools/platform/<platform>/bin/libmosek.so.6.0
for 32-bit architectures, where <platform> represents a particular UNIX platform, e.g.
Programs linking with MOSEK must be linked to several libraries. A script for linking the MOSEK examples can is located in
mosek/<version>/test/testunix.sh
This script contains the definitions:
case $MSKPLATFORM in linux32x86) MSKCC="gcc" MSKLINKFLAGS="-lc -ldl -lm" ;; linux64x86) MSKCC="gcc -m64" MSKLINKFLAGS="-lc -ldl -lm" ;; solarissparc ) MSKDIR=solaris/sparc MSKCC=cc MSKLINKFLAGS="-lsocket -lnsl -lintl -lthread -lpthread -lc -ldl -lm" ;; solarissparc64 ) MSKDIR=solaris/sparc64 MSKPLATFORM=solaris/sparc64 MSKCC="cc -xtarget=generic64" MSKLINKFLAGS="-lsocket -lnsl -lintl -lthread -lpthread -lc -ldl -lm" ;; esac
In the testunix.sh script the MSKLINKFLAGS variable is defined for each platform. MSKLINKFLAGS contains the link flags that must be added to the command line when linking against the MOSEK dynamic library.
The example directory contains makefiles for use with GNU Make.
To build the examples, open a prompt and change directory to the examples directory. For Linux with default installation path, the examples directory is
mosek/6/tools/examples/c
The directory contains a makefile for GNU Make and gcc. To build all examples, go to the examples and enter
gmake all
To build one example instead of all examples, replace “all” by the corresponding executable name. For example, to build the lo1 executable type
gmake lo1
The following example shows how to link to the MOSEK shared library on a 64bit platform:
# The -L. tells gcc to look for shared libraries in the directory ./ # The -lmosek tells gcc to link to the mosek library # Set environment variable so the MOSEK shared library # can be located. Must be done at both link time and run time. export LD_LIBRARY_PATH=./platform/linux64x86/bin/:$LD_LIBRARY_PATH # Replace -lmosek with -lmosek if you are linking on a 32-bit platform. gcc examp/lo1.c -o lo1 -I h/ -L platform/linux32x86/bin/ \ -lmosek -pthread -lc -ldl -lm # Run lo1 executable ./lo1
Please note that linking with the “-pthread” flag is requires by Intel's OpenMP library.
The distribution contains a MOSEK library built without OpenMP; to use this instead of the normal MOSEK library, replace “-lmosek” by “-lmoseknoomp, and “-lmosek64” by “-lmoseknoomp64”.
The following example shows how to link to the MOSEK shared library.
# The -L. tells cc to look for shared libraries in the directory ./ # The -lmosek tells cc to link to the mosek library. # Replace -lmosek with -lmosek64 if you are linking on a 64-bit platform. cc examp/lo1.c -o lo1 -I h/ -L platform/solaris/sparc/dll/ -lmosek \ -lsocket -lnsl -lintl -lthread -lpthread -lc -ldl -lm # Set environment variable so the MOSEK shared library # can be located. LD_LIBRARY_PATH=./platform/linux/intel/dll/:$LD_LIBRARY_PATH export LD_LIBRARY_PATH # Run lo1 executable ./lo1