Differences between revisions 20 and 21
Revision 20 as of 2016-06-13 15:04:00
Size: 3027
Comment: Indicate that mexopts.bat does not work after R2014a anymore
Revision 21 as of 2016-10-15 12:21:08
Size: 4076
Comment: Update mex instructions following https://github.com/DynareTeam/dynare/pull/1316
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
This page briefly documents how to configure MATLAB for Windows when a MEX compilation environment is required. Under Linux and MacOS, this configuration step is not necessary, because these operating systems already come with a working compilation environment (using gcc). This page briefly documents how to configure MEX compilation environment for use with the {{{use_dll}}}-option of {{{model}}}.
Line 3: Line 3:
Two compilers are currently supported: GNU C compiler (gcc) from Cygwin, and Microsoft Visual C++ (MSVC). = Octave =
Line 5: Line 5:
With Dynare, you need a working MEX compilation environment if you want to use the {{{USE_DLL}}} option of {{{model}}}. In that case, you need to tell Dynare which compiler you are using: Octave comes with capacities for compiling MEX-file. However, under Linux, you might have to install the {{{liboctave-dev}}}.

= MATLAB =

If you are using MATLAB, please check [[[http://www.mathworks.com/support/compilers| the list of supported compilers]] for your MATLAB version on your operating system. After installing your compiler, select it using {{{mex -setup}}} in Matlab and clicking on the required compiler.

== Linux ==
Under Linux you need to have a working compilation environment installed. If not already present, it can be installed via
{{{
apt-get install build-essential
}}}
(requires root privileges). This will set up {{{gcc}}}

== macOS ==
If you are using Matlab under Mac OS X, you should install the latest version of [[https://developer.apple.com/xcode/ |XCode]]


== Windows ==

Two compilers are currently supported by Matlab: Microsoft's [[https://www.visualstudio.com/| Visual C++ (MSVC)]] (free in its Commmunity edition) and, since Matlab R2015b, the MinGW-w64 C/C++
Compiler from TDM-GCC. To install this compiler, use the Add-Ons menu of MATLAB. Search for MinGW or select it from Features.
For older version of MATLAB, in particular before R2014a, it may sometimes make sense to use the GNU C compiler (gcc) from Cygwin.

Under Windows when calling Dynare with the {{{use_dll}}}-option, you need to tell Dynare which compiler you are using:
 * if you are using Microsoft Visual C++:
{{{
dynare modfilename msvc
}}}
 * if you are using MinGW:
{{{
dynare modfilename mingw
}}}
Line 10: Line 41:
 * if you are using Microsoft Visual C++:
{{{
dynare modfilename msvc
}}}
Line 15: Line 42:
= Configuring MATLAB versions before R2014a with GNU C compiler (gcc) from Cygwin = = Legacy information =

Before Matlab R2014, MEX-compiling was governed by a {{{bat}}}-file, later versions work via (more involved) {{{xml}}}-files. Here, we provide a description on how to set up Cygwin using the {{{bat}}}-file option. If you have a newer Matlab version, you have to either figure out how to translate the {{{bat}}}-file settings to {{{xml}}} or, even better, use one of the two other compilers available.

=== Configuring MATLAB versions before R2014a with GNU C compiler (gcc) from Cygwin ===
Line 18: Line 49:
 * The configuration file is called [[https://github.com/DynareTeam/dynare/raw/master/windows/mexopts-win32.bat|mexopts-win32.bat]] for MATLAB 32-bit, and [[https://github.com/DynareTeam/dynare/raw/master/windows/mexopts-win64.bat|mexopts-win64.bat]] for MATLAB 64-bit (these files are also distributed in recent packages of Dynare)  * The configuration file is called [[https://github.com/DynareTeam/dynare/raw/master/windows/mexopts-win32.bat|mexopts-win32.bat]] for MATLAB 32-bit, and [[https://github.com/DynareTeam/dynare/raw/master/windows/mexopts-win64.bat|mexopts-win64.bat]] for MATLAB 64-bit
Line 25: Line 56:
= Configuring MATLAB with Microsoft Visual C++ (MSVC) =

The following should work with recent versions of MATLAB:

 * Install Microsoft Windows SDK from [[https://www.microsoft.com/en-US/Download/details.aspx?id=8279|Microsoft Website]]
 * At MATLAB prompt, type {{{mex -setup}}}; it should autodetect MSVC, and let you select it

= Configuring MATLAB releases before R2010a with Microsoft Visual C++ (MSVC) =
=== Configuring MATLAB releases before R2010a with Microsoft Visual C++ (MSVC) ===
Line 36: Line 60:
 * For versions before 2010a, use Visual C++ 2008 Express Edition, downloadable at http://www.microsoft.com/visualstudio/en-us/products/2008-editions/express.  * For versions before 2010a, use Visual C++ 2008 Express Edition, downloadable [[http://go.microsoft.com/?linkid=7729279]|here]].

This page briefly documents how to configure MEX compilation environment for use with the use_dll-option of model.

Octave

Octave comes with capacities for compiling MEX-file. However, under Linux, you might have to install the liboctave-dev.

MATLAB

If you are using MATLAB, please check the list of supported compilers for your MATLAB version on your operating system. After installing your compiler, select it using mex -setup in Matlab and clicking on the required compiler.

Linux

Under Linux you need to have a working compilation environment installed. If not already present, it can be installed via

apt-get install build-essential

(requires root privileges). This will set up gcc

macOS

If you are using Matlab under Mac OS X, you should install the latest version of XCode

Windows

Two compilers are currently supported by Matlab: Microsoft's Visual C++ (MSVC) (free in its Commmunity edition) and, since Matlab R2015b, the MinGW-w64 C/C++ Compiler from TDM-GCC. To install this compiler, use the Add-Ons menu of MATLAB. Search for MinGW or select it from Features. For older version of MATLAB, in particular before R2014a, it may sometimes make sense to use the GNU C compiler (gcc) from Cygwin.

Under Windows when calling Dynare with the use_dll-option, you need to tell Dynare which compiler you are using:

  • if you are using Microsoft Visual C++:

dynare modfilename msvc
  • if you are using MinGW:

dynare modfilename mingw
  • if you are using Cygwin, type at the MATLAB prompt:

dynare modfilename cygwin

Legacy information

Before Matlab R2014, MEX-compiling was governed by a bat-file, later versions work via (more involved) xml-files. Here, we provide a description on how to set up Cygwin using the bat-file option. If you have a newer Matlab version, you have to either figure out how to translate the bat-file settings to xml or, even better, use one of the two other compilers available.

Configuring MATLAB versions before R2014a with GNU C compiler (gcc) from Cygwin

  • Install a Cygwin environment (see http://www.cygwin.com). If your MATLAB is 32-bit, you need the "mingw64-i686-gcc" package. If your MATLAB is 64-bit, you need the "mingw64-x86_64-gcc" package.

  • The configuration file is called mexopts-win32.bat for MATLAB 32-bit, and mexopts-win64.bat for MATLAB 64-bit

  • Rename the configuration file to mexopts.bat, and copy it to the right directory, which will be (depending on your version of Windows):

    • c:\Users\<User name>\AppData\Roaming\MathWorks\MATLAB\<release number>\ (Windows 8)

    • c:\Users\<User name>\Application Data\MathWorks\MATLAB\<release number>\ (Windows Vista/7)

    • c:\Documents and Settings\<User name>\Application Data\MathWorks\MATLAB\<release number>\ (Windows XP)

  • Note that if you installed Cygwin in a non-standard directory (i.e. elsewhere than C:\CYGWIN), you need to edit the mexopts.bat and change the set PATH=... line accordingly.

Configuring MATLAB releases before R2010a with Microsoft Visual C++ (MSVC)

Earlier versions of Matlab before R2010a do not support Visual Studio 2010:

DynareWiki: ConfigureMatlabWindowsForMexCompilation (last edited 2016-10-15 12:21:08 by JohannesPfeifer)