MATLAB Compiler | ![]() ![]() |
Compiler Restrictions
Some of the supported PC compilers have restrictions regarding their use with the MATLAB Compiler. Refer to Supported ANSI C and C++ PC Compilers for important limitation information on the supported compilers.
Choosing a Compiler
Systems with Exactly One C/C++ Compiler. If the MATLAB Compiler and your supported C or C++ compiler are installed on your system, you are ready to create C or C++ stand-alone applications. On systems where there is exactly one C or C++ compiler available to you, the mbuild
utility automatically configures itself for the appropriate compiler. So, for many users, to create a C or C++ stand-alone applications, you can simply enter
This simple method works for the majority of users. Assuming filename.c
contains a main
function, this example uses your installed C or C++ compiler as your default compiler for creating your stand-alone application. 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 Verifying mbuild. If you need to know how to change the options file or select a different compiler, continue with this section.
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 mbuild
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 your stand-alone applications.
For example, if your system has both the Lcc and Microsoft Visual C/C++ compilers, when you enter for the first time
you are asked to select which compiler to use:
Please choose your compiler for building stand-alone MATLAB applications: Select a compiler: [1] Lcc C version 2.4 in D:Applications\Mathworks\sys\lcc [2] Microsoft Visual C/C++ version 6.0 in D:\Applications\Microsoft Visual Studio [0] None Compiler:
Select the desired compiler by entering its number and pressing Return. You are then asked to verify your 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 anytime by using the setup
command.
This example shows the process of changing your default compiler to the Microsoft Visual C/C++ Version 6.0 compiler:
mbuild -setup Please choose your compiler for building stand-alone MATLAB applications. Would you like mbuild 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] Lcc C version 2.4 [9] Microsoft Visual C/C++ version 7.0 [10] Microsoft Visual C/C++ version 6.0 [11] Microsoft Visual C/C++ version 5.0 [0] None Compiler: 10 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\compopts.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 mbuild
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. This sets your default compiler's options file to your specific version. Table 4-3, Compiler Options Files on the PC, lists the names of the PC options files included in this release of MATLAB.
If you need to see which options mbuild
passes to your compiler and linker, use the verbose option, -v
, as in
to generate a list of all the current compiler settings used by mbuild
. To change the options, use an editor to make changes to your options file that corresponds to your compiler. You can also embed the settings obtained from the verbose option into an integrated development environment (IDE) or makefile that you need to maintain outside of MATLAB. Often, however, it is easier to call mbuild
from your makefile. See your system documentation for information on writing makefiles.
Combining Customized C and C++ Options Files. The options files for mbuild
have changed as of MATLAB 5.3 (Release 11) so that the same options file can be used to create both C and C++ stand-alone applications. If you have modified your own separate options files to create C and C++ applications, you can combine them into one options file.
To combine your existing options files into one universal C and C++ options file:
COMPFLAGS
, OPTIMFLAGS
, DEBUGFLAGS
, and LINKFLAGS
.
This process modifies your C options file to be a universal C/C++ options file.
Temporarily Changing the Compiler. To temporarily change your C or C++ compiler, use the -f
option, as in
The -f
option tells the mbuild 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 mbuild script to use the specified options file for the current execution of mbuild only; it does not reset the default compiler.
![]() | Building Stand-Alone Applications on PCs | Verifying mbuild | ![]() |