External Interfaces Previous page   Next Page

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.

Lcc Compiler

MATLAB includes a C compiler called Lcc that you can use to create C MEX-files. Help on using the Lcc compiler is available in a help file that ships with MATLAB. To view this file, type in the MATLAB command window

replacing the term <matlab> with the path to the directory in which MATLAB is installed on your system. (Type matlabroot in the Command Window to get the path for this directory.)

Selecting a Compiler

The mex script uses 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. If you need to compile Fortran programs, you must supply your own supported Fortran compiler.

The 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 mex -setup.

This example shows the process of setting your default compiler to the Microsoft Visual C++ Version 6.0 compiler.

If the specified compiler cannot be located, you are given the message:

Using the setup option sets your default compiler so that the new compiler is used every time you use the mex script.

Building the MEX-File on Windows

There is example C source code, yprime.c, and its Fortran counterpart, yprimef.f and 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.


Previous page  Testing Your Configuration on UNIX Specifying an Options File Next page

© 1994-2005 The MathWorks, Inc.