External Interfaces/API |
Testing Your Configuration on UNIX
The quickest way to check if your system is set up properly to create MEX-files is by trying the actual process. There is C source code for an example, 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 files, yprime.c
or yprimef.F
and yprimefg.F
, on UNIX, you must first copy the file(s) to a local directory, and then change directory (cd
) to that local directory.
This uses the system compiler to create the MEX-file called yprime
with the appropriate extension for your system.
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, 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.
Selecting a Compiler
To change your default compiler, you select a different options file. You can do this anytime by using the command
mex -setup Using the 'mex -setup' command selects an options file that is placed in ~/matlab and used by default for 'mex'. An options file in the current working directory or specified on the command line overrides the default options file in ~/matlab. Options files control which compiler to use, the compiler and link command options, and the runtime libraries to link against. To override the default options file, use the 'mex -f' command (see 'mex -help' for more information). The options files available for mex are: 1: <matlab>/bin/gccopts.sh : Template Options file for building gcc MEXfiles 2: <matlab>/bin/mexopts.sh : Template Options file for building MEXfiles using the system ANSI compiler Enter the number of the options file to use as your default options file:
Select the proper options file for your system by entering its number and pressing Return. If an options file doesn't exist in your MATLAB directory, the system displays a message stating that the options file is being copied to your user-specific matlab
directory. If an options file already exists in your matlab
directory, the system prompts you to overwrite it.
Using the setup option resets your default compiler so that the new compiler is used every time you use the mex
script.
Building MEX-Files | Testing Your Configuration on Windows |