Using the C Math Library    

Configuring the Build Environment 

mbuild determines whether to compile in C or C++ by examining the type of files you are compiling. Table 2-1 shows the supported file extensions. If you include both C and C++ files, mbuild uses the C++ compiler and the MATLAB C++ Math Library. If mbuild cannot deduce from the file extensions whether to compile in C or C++, mbuild invokes the C compiler.

Table 2-1: UNIX File Extensions for mbuild
Language
Extension(s)
C
.c
C++
.cpp
.C
.cxx
.cc

Locating Options Files

mbuild locates your options file by searching the following:

mbuild uses the first occurrence of the options file it finds. If no options file is found, mbuild displays an error message.

Using the System Compiler

If your supported C compiler is installed on your system, you are ready to create 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.

Changing the Default Compiler

You need to use the setup option if you want to change your default compiler. At the UNIX prompt type:

The setup option creates a user-specific options file for your ANSI C or C++ compiler. Using the setup option sets your default compiler so that the new compiler is used every time you use the mbuild script.

Executing mbuild -setup presents a list of options files currently included in the bin subdirectory of MATLAB.

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.

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/R12/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 UNIX Applications Building an Application