Differences between revisions 1 and 21 (spanning 20 versions)
Revision 1 as of 2009-12-09 11:05:31
Size: 1603
Comment:
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 g++). This page briefly documents how to configure MEX compilation environment for use with the {{{use_dll}}}-option of {{{model}}}.
Line 3: Line 3:
With Dynare, you need a working MEX compilation environment in two cases:
 * you need to recompile Dynare MEX files, without using Dynare build system
 * you want to use the {{{USE_DLL}}} option of {{{model}}}, or the {{{k_order_solver}}} option of {{{stoch_simul}}}
= Octave =
Line 7: Line 5:
We describe here the installation of two compilers: GNU C++ compiler (g++), and Microsoft Visual C++ (MSVC). Octave comes with capacities for compiling MEX-file. However, under Linux, you might have to install the {{{liboctave-dev}}}.
Line 9: Line 7:
Note that for {{{USE_DLL}}} and {{{k_order_solver}}}, the only supported compiler is g++ = MATLAB =
Line 11: Line 9:
= Configuring MATLAB with GNU C++ compiler (g++) = 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.
Line 13: Line 11:
 * Install a Cygwin environment (see http://www.cygwin.com). You need at least the following packages: gcc, gcc-g++, gcc-mingw, gcc-mingw-g++
 * Download [[attachment:mexopts.bat]], and put it in {{{c:\Documents and Settings\<User name>\Application Data\MathWorks\MATLAB\<release number>\}}}
== 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}}}
Line 16: Line 18:
= Configuring MATLAB with Microsoft Visual C++ (MSVC) = == macOS ==
If you are using Matlab under Mac OS X, you should install the latest version of [[https://developer.apple.com/xcode/ |XCode]]
Line 18: Line 21:
The following should work with recent versions of MATLAB:
Line 20: Line 22:
 * Install Visual C++ 2008 Express Edition, downloadable at http://www.microsoft.com/Express/VC/
 * At MATLAB prompt, type {{{mex -setup}}}; it should autodetect MSVC, and let you select it
 * For users of MATLAB 64-bit, please follow [[http://www.mathworks.fr/support/solutions/en/data/1-6IJJ3L/index.html?solution=1-6IJJ3L|these instructions]] for finishing the installation
== 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
}}}
 * 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 [[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
 * 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:
 * For Matlab 2010a there is a patch available at http://www.mathworks.de/support/solutions/en/data/1-D5W493/?solution=1-D5W493.
 * For versions before 2010a, use Visual C++ 2008 Express Edition, downloadable [[http://go.microsoft.com/?linkid=7729279]|here]].
 * For users of MATLAB 64-bit releases before R2010a, please follow [[http://www.mathworks.fr/support/solutions/en/data/1-6IJJ3L/index.html?solution=1-6IJJ3L|these instructions]] for finishing the installation.

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)