MATLAB Compiler    

mex Verification

Choosing a Compiler

Systems with Exactly One C/C++ Compiler.   If you have properly installed the MATLAB Compiler and your supported C or C++ compiler, you can now create C MEX-files. On systems where there is exactly one C or C++ compiler available to you, the mex utility automatically configures itself for the appropriate compiler. So, for many users, to create a C MEX-file, you can simply enter

This simple method of creating MEX-files works for the majority of users. It uses your installed C or C++ compiler as your default compiler for creating your MEX-files.

If you are a user who does not need to change compilers, or you do not need to modify your compiler options files, you can skip ahead in this section to Creating MEX-Files.

Systems with More than One C/C++ Compiler.   On systems where there is more than one C or C++ compiler, the mex utility lets you select which of the compilers you want to use. Once you choose your C or C++ compiler, that compiler becomes your default compiler and you no longer have to select one when you compile MEX-files.

For example, if your system has both the Borland and Watcom compilers, when you enter for the first time

you are asked to select which compiler to use.

Select the desired compiler by entering its number and pressing Return. You are then asked to verify the information.

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 any time by using the mex -setup option.

This example shows the process of changing your default compiler to the Microsoft Visual C/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 everytime 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.

The setup option copies the appropriate options file to your user profile directory. To make your user-specific changes to the options file, you edit your copy of the options file in your user profile directory to correspond to your specific needs and save the modified file. After completing this process, the mex script will use the new options file everytime with your modified settings.

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

The <matlab>\extern\examples\mex directory contains C source code for the example yprime.c. To verify that your system can create MEX-files, enter at the MATLAB prompt

This should create the yprime.dll MEX-file. MEX-files created on Windows always have the extension dll.

You can now call yprime 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.

MATLAB Add-In for Visual Studio

The MathWorks provides a MATLAB add-in for the Visual Studio development system that lets you work easily within the Microsoft Visual C/C++ (MSVC) environment to create and debug MEX-files. The MATLAB add-in for Visual Studio is included with MATLAB and is automatically installed when you run mex -setup and select Microsoft Visual C/C++ version 5 or 6. For more information about the add-in, see Using an Integrated Development Environment.


  Installation MATLAB Compiler Verification