MATLAB Compiler    

Preparing to Compile

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.

Other restrictions include

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.

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:

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:

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 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.

Table 4-3: Compiler Options Files on the PC  
Compiler
Master Options File
Borland C++Builder, Version 3.0
bcc53compp.bat
Borland C++Builder, Version 4.0
bcc54compp.bat
Borland C++Builder, Version 5.0
bcc55compp.bat
Borland C++Builder, Version 6.0
bcc56compp.bat
Lcc C, Version 2.4
lccopts.bat
Microsoft Visual C/C++, Version 5.0
msvc50compp.bat
Microsoft Visual C/C++, Version 6.0
msvc60compp.bat
Microsoft Visual C/C++, Version 7.0
msvc70compp.bat

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:

  1. Copy from the C++ options file to the C options file all lines that set the variables COMPFLAGS, OPTIMFLAGS, DEBUGFLAGS, and LINKFLAGS.
  2. In the C options file, within just those copied lines from step 1, replace all occurrences of:

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