MATLAB C/C++ Graphics Library | ![]() ![]() |
Building Graphics Applications on a PC
To create a stand-alone graphics application on a PC, you must use the MATLAB Compiler (mcc
), specifying the Compiler's Graphics Library bundle file.
Bundle files are ASCII text files that contain Compiler command line options and arguments. The MATLAB Compiler supports separate bundle files for creating C stand-alone graphics applications and C++ applications.
C applications |
<MATLAB>\toolbox\compiler\bundles\sgl |
C++ applications |
<MATLAB>\toolbox\compiler\bundles\sglcpp |
For example, to convert the Lorenz application into a stand-alone application, enter these commands at the MATLAB prompt.
mbuild -setup !copy <MATLAB>\toolbox\matlab\demos\lorenz.m . mcc -B sgl lorenz.m !lorenz
mbuild
-setup
to set up the environment to create stand-alone applications. This is only required the first time you create a stand-alone graphics application. See Configuring the MATLAB C/C++ Graphics Library for more information about mbuild.copy
command to copy the Lorenz application M-file into the current MATLAB directory. Replace <MATLAB>
with the name of your top-level MATLAB installation directory. (This is suggested because you may not have permission to create a new file in the MATLAB demos
directory.) You can also use Microsoft Windows Explorer to copy the file.-B
flag to specify the bundle file used to create C stand-alone graphics applications, sgl
.Results of Compilation
The MATLAB Compiler generates multiple C or C++ source code modules in your current working directory. These include wrapper files that contain necessary components of a stand-alone application, such as a main()
entry point.
In addition, the first time you run the MATLAB Compiler to create a stand-alone graphics application, it creates a subdirectory, named \bin
, in your current working directory. The Compiler puts in this directory versions of the MATLAB menu bar and toolbar figure files that are used by stand-alone graphics applications at run-time. (Stand-alone graphics applications use a special menu bar and toolbar. For more information, see Changes in Run-Time Behavior and Appearance.) Subsequently, whenever you run the Compiler, it checks for the existence of these files in the \bin
directory and does not overwrite them if they exist.
Running a Stand-Alone Graphics Application
The Compiler creates the stand-alone graphics application as an executable program in your current working directory, giving it the same name as your M-file, but with the .exe
filename extension. You can run the application at the MATLAB command prompt if you precede the name with a !
symbol, as shown in the example. You can also run stand-alone graphics applications outside the MATLAB environment. However, make sure that the directory containing the shared libraries to which your application has been linked (<MATLAB>\bin
) is on your directory search path.
Editing the Search Path on Windows 95. On Window 95 systems, you must edit your autoexec.bat
file to add the shared library directory to the PATH
variable.
Editing the Search Path on Windows NT. On Windows NT systems, go the Settings option on the Start menu and choose Control Panel. Double-click on the System icon to view the System Properties dialog box. Use the Environment panel to edit the PATH
variable.
![]() | Building a Stand-Alone Graphics Application | Building Graphics Applications on a UNIX System | ![]() |