Testing Your Configuration on Windows
Before you can create MEX-files on the Windows platform, you must configure the default options file,
mexopts.bat, for your compiler. The switch,
setup, provides an easy way for you to configure the default options file. To configure or change the options file at anytime, run
from either the MATLAB or DOS command prompt.
Selecting a Compiler
MATLAB includes a C compiler, Lcc, that you can use to create C MEX-files. The
mex script will use the Lcc compiler automatically if you do not have a C or C++ compiler of your own already installed on your system and you try to compile a C MEX-file. Naturally, if you need to compile Fortran programs, you must supply your own supported Fortran compiler.
mex script uses the filename extension to determine the type of compiler to use for creating your MEX-files. For example,
would use your Fortran compiler and
would use your C compiler.
On Systems without a Compiler. If you do not have your own C or C++ compiler on your system, the
mex utility automatically configures itself for the included Lcc compiler. So, to create a C MEX-file on these systems, you can simply enter
This simple method of creating MEX-files works for the majority of users.
If using the included Lcc compiler satisfies your needs, you can skip ahead in this section to Building the MEX-File on Windows.
On Systems with a Compiler. On systems where there is a C, C++, or Fortran compiler, you can select which compiler you want to use. Once you choose your compiler, that compiler becomes your default compiler and you no longer have to select one when you compile MEX-files. To select a compiler or change to existing default compiler, use
This example shows the process of setting your default compiler to the Microsoft Visual C++ Version 6.0 compiler.
mex -setup Please choose your compiler for building external interface (MEX) files. Would you like mex to locate installed compilers [y]/n? n Select a compiler:  Compaq Visual Fortran version 6.6  Lcc C version 2.4  Microsoft Visual C/C++ version 6.0  None Compiler: 3 Your machine has a Microsoft Visual C/C++ compiler located at D:\Applications\Microsoft Visual Studio. Do you want to use this compiler [y]/n? y Please verify your choices: Compiler: Microsoft Visual C/C++ 6.0 Location: C:\Program Files\Microsoft Visual Studio Are these correct?([y]/n): y The default options file: "C:\WINNT\Profiles\username\ApplicationData\MathWorks\MATLAB\R1 3\mexopts.bat" is being updated from ...
If the specified compiler cannot be located, you are given the message:
setup option sets your default compiler so that the new compiler is used every time you use the
Building the MEX-File on Windows
There is example C source code,
yprime.c, and its Fortran counterpart,
yprimefg.f, included in the
<matlab>\extern\examples\mex directory, where
<matlab> represents the top-level directory where MATLAB is installed on your system.
To compile and link the example source file on Windows, at the MATLAB prompt, type
This should create the MEX-file called
yprime with the
.DLL extension, which corresponds to the Windows platform.
You can now call
yprime as if it were an M-function.
To try the Fortran version of the sample program with your Fortran compiler, switch to your Fortran compiler using
mex -setup. Then, at the MATLAB prompt, type
In addition to running the
mex script from the MATLAB prompt, you can also run the script from the system prompt.
|Testing Your Configuration on UNIX||Specifying an Options File|