4. Testing installation and compiling examples


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.

4.1. Setting up 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.

4.1.1. Windows: Checking the MOSEK installation

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.

  1. Open a DOS command prompt (DOS box).
  2. 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]
    
  3. Verify that

    • The program is executed. If the system was unable to recognize mosek.exe as a valid command, then the PATH environment variable has not been set correctly.
    • The MOSEK version printed matches the expected version.
    • The MOSEKLM_LICENSE_FILE points to the correct license file or to the directory containing it. Note that if it points to a directory containing several license files, there is a risk that it will use the wrong one.
    • The PATH contains the path to the correct MOSEK installation.

4.1.2. Linux: Checking the MOSEK installation

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:

  1. Open a command prompt.
  2. 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]
    
  3. Verify that

    • The program is executed. If the system was unable to locate mosek, then the PATH environment variable bas not been set correctly.
    • The MOSEK version printed matches the expected version.
    • The MOSEKLM_LICENSE_FILE points to the correct license file or to the directory containing it. If it points to a directory containing several license files, there is a risk that it will use the wrong one.
    • The LD_LIBRARY_PATH contains the path to the correct MOSEK installation.

4.1.3. MacOSX: Checking the MOSEK installation

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.

  1. Open a command prompt.
  2. Enter

    mosek -f
    

    This will execute the MOSEK command line tool and print some relevant information.

  3. Verify that

    • The program was executed. If the system was unable to locate mosek, then the PATH environment variable was not correctly set.
    • The MOSEK version printed matches the expected version.
    • The MOSEKLM_LICENSE_FILE points to the correct license file or the directory containing it. If it points to a directory containing several license files, there is a risk that it will use to wrong one.
    • The DYLD_LIBRARY_PATH should contain the path to the correct MOSEK installation.

4.2. Compiling and linking

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.

4.2.1. Compiling under Microsoft Windows

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

4.2.1.1. Compiling examples using NMake

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

4.2.1.2. Compiling from command line

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:

  1. Change directory:

    c:
    cd "\Program Files\mosek\6\tools"
    
  2. 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
    
  3. To run the compiled examples, enter

    ./lo1.exe
    

4.2.1.3. Adding MOSEK to a Visual Studio Project

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:

  • 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[[MathCmd 1]]C/C++[[MathCmd 1]]General.
  • In the properties view select Additional Include Directories and click on the ellipsis “...”.
  • 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
    
  • Click OK.
  • Back in the Property Pages dialog select from the tree-view Configuration Properties[[MathCmd 1]]Linker[[MathCmd 1]]Input.
  • In the properties view select Additional Dependencies and click on the ellipsis “...”. This will open the Additional Dependencies dialog.
  • 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
    
  • Click OK.
  • Back in the Property Pages dialog click OK.

Additionally, if you want to add the mosek.h header file to your project, do the following:

  • In the Solution Explorer right-click on the relevant project and select Add[[MathCmd 1]]Add Existing Item.
  • Locate and select the mosek.h header file and click OK.

4.2.2. UNIX versions

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.

  • linux32x86,
  • linux64x86,
  • osx32ppc,
  • osx32x86,
  • solarissparc, or
  • solarissparc64.

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.

4.2.2.1. Compiling examples using GMake

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

4.2.2.2. Example: Linking with GNU C under Linux

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

4.2.2.3. Example: Linking with Sun C on Solaris

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
Wed Feb 29 16:08:50 2012