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\5\
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 5.0.0.2(alpha) (Build date: Nov 16 2006 10:24:36) 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 13:28:28. Using FLEXlm version: 11.3. Hostname: 'skalbjerg' Hostid: '"000c6e5cab33 005056c00001 005056c00008"' Operating system variables MOSEKLM_LICENSE_FILE : C:\Program Files\mosek\5\licenses PATH : c:\local\python24;c:\local\bin;C:\Program Files\mosek\5\tools\platform\win\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\5
and that the platform-specific files are located in
c:\Program Files\mosek\5\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\5\tools\examples\c
The directory contains several makefiles. You should use either Makefile.win32x86 or Makefile.win64x86, depending on your () installation. For 32-bit Windows type
nmake /f Makefile.win32x86 all
and similarly for 64-bit Windows, type
nmake /f Makefile.win64x86 all
To only build a single example instead of all examples, replace “all” by the corresponding executable name. For example, to build lo1.exe on 32-bit Windows, type
nmake /f Makefile.win32x86 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\5\tools\platform\<platform>\h\mosek.h
The MOSEK lib file located in
c:\Program Files\mosek\5\platform\<platform>\dll
The relevant lib file is
on 64-bit Microsoft Windows (AMD x64 or Intel EMT64)
mosek64_5_0.lib
on 32-bit Microsoft Windows
mosek5_0.lib
The MOSEK solver dll located in
c:\Program Files\mosek\5\platform\<platform>\bin
The relevant dll file is
on 64-bit Microsoft Windows (AMD x64 or Intel EMT64)
mosek64_5_0.dll
on 32-bit Microsoft Windows
mosek5_0.dll
Finally, the distributed C examples are located in the directory
c:\Program Files\mosek\5\tools\examples\c
To compile and execute the distributed example lo1.c, do the following:
Change directory:
c: cd "\Program Files\mosek\5\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\<platform>\h\mosek.h platform\win\dll\mosek5_0.lib
For Windows 64:
cl examples\c\lo1.c /out:lo1.exe /I platform\<platform>\h\mosek.h platform\win64x86\dll\mosek64_5_0.lib
For Windows Itanium:
cl examples\c\lo1.c /out:lo1.exe /I platform\<platform>\h\mosek.h platform\winia64\dll\mosek64_5_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\5\tools\platform\win\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\5\tools\platform\win\dll\mosek5_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/5/tools/h/mosek.h
and the MOSEK shared (or dynamic) library is located in
mosek/5/tools/platform/<platform>/bin/libmosek64.so.5.0
for 64-bit architectures, and in
mosek/5/tools/platform/<platform>/bin/libmosek.so.5.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="-lpthread -lc -ldl -lm" ;; linux64x86) MSKCC="gcc -m64" MSKLINKFLAGS="-lpthread -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/5/tools/examples/c
The directory contains several makefiles. You should use either Makefile.lnx32x86 or Makefile.lnx64x86, depending on your installation. For 32-bit Linux, type
gmake -f Makefile.lnx32x86 all
and similarly for 64-bit Windows, type
gmake -f Makefile.lnx64x86 all
To build one example instead of all examples, replace “all” by the corresponding executable name. For example, to build the lo1 executable on 32-bit Linux, type
gmake -f Makefile.lnx64x86 lo1
The following example shows how to link to the MOSEK shared library.
# 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/linux32x86/bin/:$LD_LIBRARY_PATH # Replace -lmosek with -lmosek64 if you are linking on a 64-bit platform. gcc examp/lo1.c -o lo1 -I h/ -L platform/linux32x86/bin/ \ -lmosek -lpthread -lc -ldl -lm # Run lo1 executable ./lo1
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