External Interfaces |
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
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.
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: [1] Compaq Visual Fortran version 6.6 [2] Lcc C version 2.4 [3] Microsoft Visual C/C++ version 6.0 [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:
The default location for compiler-name is directory-name, but that directory does not exist on this machine. Use directory-name anyway [y]/n?
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.
Testing Your Configuration on UNIX | Specifying an Options File |
© 1994-2005 The MathWorks, Inc.