MATLAB Compiler | ![]() ![]() |
Preparing to Compile
Note Refer to Supported ANSI C and C++ UNIX Compilers for information about supported compilers and important limitations. |
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 or C++ stand-alone applications. To create a stand-alone C application, you can simply enter
This simple method works for the majority of users. Assuming filename.c
contains a main
function, this example uses the system's compiler as your default compiler for creating your stand-alone application. If you are a user who does 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 Verifying mbuild. If you need to know how to change the options file or select a different compiler, continue with this section.
Changing Compilers
Changing the Default Compiler. You need to use the setup
option if you want to change any options or link against different libraries. At the UNIX prompt type
The setup
option creates a user-specific options file for your ANSI C or C++ compiler. Executing mbuild -setup
presents a list of options files currently included in the bin
subdirectory of MATLAB:
mbuild -setup Using the 'mbuild -setup' command selects an options file that is placed in ~/.matlab/R13 and used by default for 'mbuild'. An options file in the current working directory or specified on the command line overrides the default options file in ~/.matlab/R13. Options files control which compiler to use, the compiler and link command options, and the runtime libraries to link against. To override the default options file, use the 'mbuild -f' command (see 'mbuild -help' for more information). The options files available for mbuild are: 1: /matlab/bin/mbuildopts.sh : Build and link with MATLAB C/C++ Math Library Enter the number of the options file to use as your default options file:
If there is more than one options file, you can select the one you want by entering its number and pressing Return. If there is only one options file available, it is automatically copied to your MATLAB directory if you do not already have an mbuild
options file. If you already have an mbuild
options file, you are prompted to overwrite the existing one.
Note
The options file is stored in the .matlab/R13 subdirectory of your home directory. This allows each user to have a separate mbuild configuration.
|
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.
If you need to change the options that mbuild
passes to your compiler or linker, you must first run
which copies a master options file to your local MATLAB directory, typically $HOME/.matlab/R13/mbuildopts.sh
.
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. To change the options, use an editor to make changes to your options file, which is in your local matlab
directory. Your local matlab
directory is a user-specific, MATLAB directory in your individual home directory that is used specifically for your individual options files. You can also embed the settings obtained from the verbose option of mbuild
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.
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 UNIX | Verifying mbuild | ![]() |