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.
Language |
Extension(s) |
C |
.c |
C++ |
.cpp |
Note
You can override the language choice that is determined from the extension by using the -lang option of mbuild . For more information about this option, as well as all of the other mbuild options, see Table 2-5.
|
Locating Options Files
To locate your options file, the mbuild
script searches the following:
Profiles
directory <matlab>\bin
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, namedApplication 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
mbuild filename.c
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
mbuild filename.c
you are asked to select which compiler to use.
mbuild has detected the following compilers on your machine: [1] : Borland compiler in T:\Borland\BC.500 [2] : MSVC compiler in T:\DevStudio\c.106 [0] : None Please select a compiler. This compiler will become the default:
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.
mbuild -setup Please choose your compiler for building standalone MATLAB applications. Would you like mbuild to locate installed compilers [y]/n? n Choose your C/C++ compiler: [1] Borland C/C++ (version 5.0, 5.2, or 5.3) [2] Microsoft Visual C/C++ (version 4.2, 5.2, or 6.0) [0] None Compiler: 2 Choose the version of your C/C++ compiler: [1] Microsoft Visual C/C++ 4.2 [2] Microsoft Visual C/C++ 5.0 [3] Microsoft Visual C/C++ 6.0 version: 3 Your machine has a Microsoft Visual C/C++ compiler located at D:\Program Files\DevStudio6. Do you want to use this compiler [y]/n? y Please verify your choices: Compiler: Microsoft Visual C/C++ 6.0 Location: D:\Program Files\DevStudio6 Are these correct?([y]/n): y The default options file: "C:\WINNT\Profiles\username \Application Data\MathWorks\MATLAB\R12\compopts.bat" is being 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 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
mbuild -v filename1
[filename2 ...]
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.
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:
COMPFLAGS
, OPTIMFLAGS
, DEBUGFLAGS
, and LINKFLAGS
.
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
mbuild -f <file> ...
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 | ![]() |