MATLAB Compiler | ![]() ![]() |
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.
Note
On Windows 98 systems, if you get the error, out of environment space , see Out of Environment Space Running mex or mbuild for more information.
|
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.
mex has detected the following compilers on your machine: [1] : Borland compiler in T:\Borland\BC.500 [2] : WATCOM compiler in T:\watcom\c.106 [0] : None Please select a compiler. This compiler will become the default:
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.
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] Borland C++Builder version 6.0 [2] Borland C++Builder version 5.0 [3] Borland C++Builder version 4.0 [4] Borland C++Builder version 3.0 [5] Borland C/C++ version 5.02 [6] Borland C/C++ version 5.0 [7] Borland C/C++ (free command line tools) version 5.5 [8] Compaq Visual Fortran version 6.6 [9] Compaq Visual Fortran version 6.1 [10] Digital Visual Fortran version 6.0 [11] Digital Visual Fortran version 5.0 [12] Lcc C version 2.4 [13] Microsoft Visual C/C++ version 7.0 [14] Microsoft Visual C/C++ version 6.0 [15] Microsoft Visual C/C++ version 5.0 [16] WATCOM C/C++ version 11 [17] WATCOM C/C++ version 10.6 [0] None Compiler: 14 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: D:\Applications\Microsoft Visual Studio Are these correct?([y]/n): y The default options file: "C:\WINNT\Profiles\username \Application Data\MathWorks\MATLAB\R13\mexopts.bat" is being updated... Installing the MATLAB Visual Studio add-in ... Updated ...
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 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.
Note The MATLAB add-in for Visual Studio does not currently work with Microsoft Visual C/C++, Version 7.0. |
![]() | Installation | MATLAB Compiler Verification | ![]() |