MATLAB Compiler    

mex Verification

Choosing a Compiler

Using the System Compiler.   If the MATLAB Compiler and your supported C or C++ compiler are installed on your system, you are ready to create C MEX-files. To create a MEX-file, you can simply enter

This simple method of creating MEX-files works for the majority of users. It uses the system's compiler as your default compiler for creating C MEX-files.

If you do not need to change C or C++ compilers, or you do not need to modify your compiler options files, you can skip ahead in this section to Creating MEX-Files. If you need to know how to change the options file, continue with this section.

Changing Compilers

Changing the Default Compiler.   To change your default C or C++ compiler, you select a different options file. You can do this at anytime by using the command

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.

Modifying the Options File.   Another use of the setup option is if you want to change your options file settings. For example, if you want to make a change to the current linker settings, or you want to disable a particular set of warnings, you should use the setup option.

As the previous note says, setup copies the appropriate options file to your individual directory. To make your user-specific changes to the options file, you then edit your copy of the options file to correspond to your specific needs and save the modified file. This sets your default compiler's options file to your specific version.

Temporarily Changing the Compiler.   To temporarily change your C or C++ compiler, use the -f option, as in

The -f option tells the mex script to use the options file, <file>. If <file> is not in the current directory, then <file> must be the full pathname to the desired options file. Using the -f option tells the mex script to use the specified options file for the current execution of mex only; it does not reset the default compiler.

Creating MEX-Files

To create MEX-files on UNIX, first copy the source file(s) to a local directory, and then change directory (cd) to that local directory.

On UNIX, MEX-files are created with platform-specific extensions, as shown in Table 2-2, MEX-File Extensions for UNIX.

Table 2-2: MEX-File Extensions for UNIX  
Platform
MEX-File Extension
Dec/Compaq Alpha
mexaxp
HP 9000 PA-RISC
mexhp7
HP-UX
mexhpux
IBM RS/6000
mexrs6
Linux
mexglx
SGI
mexsg
Solaris
mexsol

The <matlab>/extern/examples/mex directory contains C source code for the example yprime.c. After you copy the source file (yprime.c) to a local directory and cd to that directory, enter at the MATLAB prompt

This should create the MEX-file called yprime with the appropriate extension corresponding to your UNIX platform. For example, if you create the MEX-file on Solaris, its name is yprime.mexsol.

You can now call yprime from the MATLAB prompt as if it were an M-function. For example:

If you encounter problems generating the MEX-file or getting the correct results, refer to External Interfaces/API in the MATLAB documentation for additional information about MEX-files.


  Installation MATLAB Compiler Verification