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 file extensions that mbuild interprets as indicating C or C++ files. 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-3: Windows File Extensions for mbuild
Language
Extension(s)
C
.c
C++
.cpp
.cxx
.cc

Locating Options Files

To locate your options file, the mbuild script searches the following:

mbuild uses the first occurrence of the options file it finds. If no options file is found, mbuild searches your machine for a supported C compiler and uses the factory default options file for that compiler. If multiple compilers are found, you are prompted to select one.

The User Profile Directory Under Windows.   The Windows user Profiles directory is a directory that contains user-specific information such as Desktop appearance, recently used files, and Start Menu items. The mbuild utility stores its options file compopts.bat that is created during the -setup process in a subdirectory of your user Profiles directory, named
Application Data\MathWorks\MATLAB\R12.

Under Windows NT and Windows 95/98 with user profiles enabled, your user profile directory is %windir%\Profiles\username. Under Windows 95/98 with user profiles disabled, your user profile directory is %windir%. Under Windows 95/98, you can determine whether or not user profiles are enabled by using the Passwords control panel.

Systems with Exactly One C/C++ Compiler

If your supported C compiler is installed on your system, you are ready to create C stand-alone applications. On systems where there is exactly one C compiler available to you, the mbuild utility automatically configures itself for the appropriate compiler. So, for many users, to create a C stand-alone application, you can simply enter

This simple method works for the majority of users. It uses your installed C compiler as your default compiler for creating your stand-alone applications.

Systems with More than One Compiler

On systems where there is more than one C compiler, the mbuild utility lets you select which of the compilers you want to use. Once you choose your 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 Borland and Microsoft 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 the Default Compiler

To change your default C compiler, you select a different options file. You can do this at any time 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 every time 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 the current linker settings, or you want to disable a particular set of warnings, use the setup option.

The setup option copies the appropriate options file to your user profile directory and names it compopts.bat. Make your user-specific changes to compopts.bat in the user profile directory and save the modified file. This sets your default compiler's options file to your specific version.

Table 2-4, Compiler Options Files on the PC lists the names of the PC master options files included in this release of the MATLAB C Math Library.

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.

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 2-4: Compiler Options Files on the PC
Compiler
Master Options File
Borland C/C++, Version 5.0
bcccompp.bat
Borland C/C++, Version 5.2
bcc52compp.bat
Borland C++Builder 3.0
bcc53compp.bat
Borland C++Builder 4.0
bcc54compp.bat
Borland C++Builder 5.0
bcc55compp.bat
Lcc 2.4 (bundled with MATLAB)
lcccompp.bat
Microsoft Visual C/C++, Version 5.0
msvc50compp.bat
Microsoft Visual C/C++, Version 6.0
msvc60compp.bat

Combining Customized C and C++ Options Files

The same options files 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 COMPFLAGS with CPPCOMPFLAGS, OPTIMFLAGS with CPPOPTIMFLAGS, DEBUGFLAGS with CPPDEBUGFLAGS, and LINKFLAGS with CPPLINKFLAGS.

This process modifies your C options file to be a universal C/C++ options file.

Temporarily Changing the Compiler

To temporarily change your 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 Microsoft Windows Applications Building an Application