ApCoCoA-1:HowTo:Compile MatlabToolbox on Windows

From ApCoCoAWiki
Revision as of 15:45, 10 November 2008 by Matthias Machnik (talk | contribs) (Code appearance changed)

Introduction

  • This site is set up to collect all necessary bits and pieces to compile the MatlabToolbox on Windows.
  • This description is made for compiling the MatlabToolbox with MSVC 2003 Express and Matlab 2007b.

Preparation

Before compiling the MatlabToolbox you need to install the following files/libraries:

  • CoCoALib: Find a description on how to install the CoCoALib on Windows here.
  • ApCoCoALib: Find a description on how to install the ApCoCoALib on Windows here.
  • HG mercurial: You will need this software to download the latest MatlabToolbox from a repository. The MatlabToolbox is managed with the source control system mercurial. We will refer to TortoiseHG. TortoiseHG will install mercurial on your system and adds a context menu in the MS Explorer providing many of the needed functionalities.
    • Download TortoiseHG here.
    • A more detailed documentation on you how to use mercurial can be found here.

Download Instructions

Get the latest MatlabToolbox version from the repo site. A brief instruction using TortoiseHG is:

  • Add a folder on your local harddisk for the local repo copy.
  • Open the context menu entry TortoiseHG->Clone a repository.
    • As the source path copy the selected link from the repo site.
    • As the destination path select your created folder.
    • Start the download of the ApCoCoALib with the clone button.

Compilation Instructions

Before compiling you have to set up the right compiler in Matlab and adjust the makefile configuration.

Mex Compiler

The MatlabToolbox will use the mex.bat to generate mex files. MSVC has to be defined as the default mex compiler.

To do so open the Matlab command prompt and type in: mex -setup

The following information and dialogs will display. Choose the right options as shown.

mex -setup
Please choose your compiler for building external interface (MEX) files: 
 
Would you like mex to locate installed compilers [y]/n? y
 
Select a compiler: 
[1] Lcc C version 2.4.1 in C:\PROGRA~1\MATLAB\R2006b\sys\lcc 
[2] Microsoft Visual C/C++ version 8.0 in C:\Programme\Microsoft Visual Studio 8 
 
[0] None 
 
Compiler: 2
 
Please verify your choices: 
 
Compiler: Microsoft Visual C/C++ 8.0 
Location: C:\Programme\Microsoft Visual Studio 8 
 
Are these correct?([y]/n): y

Config File

Prior to compilation you have to adjust the makefile. Open the file makefile.vc in the ApCoCoALibToolbox subfolder.

Set the include and lib pathes to your local pathes. The relevant section is indicated by

#-------------------------------------------------------------------------------
# Adjust the following names and pathes
#-------------------------------------------------------------------------------

...

#-------------------------------------------------------------------------------

Compilation

Open a Visual Studio command prompt and change to your local ApCoCoALib folder. Use the nmake command to compile the MatlabToolbox : <c>nmake -f Makefile.vc</c> Will display all available targets. <c>nmake -f Makefile.vc toolbox</c> Will build the MatlabToolbox DLL. <c>nmake -f Makefile.vc mex</c> Will build the MatlabToolbox mex files.

Note: The mex files can be called in Matlab as usual Matlab functions.

Setting Path Variables

Windows Path Settings

In order to use the generated ApCoCoALibToolBox.dll this file has to be made known to the system. Add the following path to the System Variable Path: %ToolboxPath\ApCoCoALibToolBox (%ToolboxPath stands for your local MatlabToolbox repository folder). You can set the path e.g. using the windows gui provided at:

  • right-click My Computer icon, select Properties,
  • click Start > Control Panel > System icon
  • Click the Advanced tab

Matlab Path Settings

To use the mex files and the classes provided by the MatlabToolbox three pathes have to be added to the Matlab Path-Variable. Open File->Set Path and add the following three folders (%ToolboxPath stands for your local MatlabToolbox repository folder):

  • %ToolboxPath
  • %ToolboxPath\MatlabFiles
  • %ToolboxPath\MexFiles

Problems

If you encounter problems check out the forum: ApCoCoA Forum