MATLAB C/C++ Graphics Library | ![]() ![]() |
Building Graphics Applications on a UNIX System
To create a stand-alone graphics application on a UNIX system, 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 !cp <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
.cp
command to copy the Lorenz application M-file into the current MATLAB directory. Use the ! symbol to execute an operating system command inside the MATLAB environment. (This is suggested because you may not have permission to create a new file in the MATLAB demos
directory.) Replace <MATLAB>
with the name of your top-level MATLAB installation directory.-B
flag to specify the bundle 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, when 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. You can run your stand-alone graphics application at the MATLAB prompt if you precede the executable name with a !
, as shown in the example. You can also run a stand-alone application outside of the MATLAB environment. However, you must add to your path the location of the shared libraries to which your application is linked. To set your path, use the command from this table that is specific for your system.
To avoid having to reissue this command at the start of each login session, include it in a startup script such as ~/.cshrc or ~/.login
. Use the ~/.login
option, if your system supports it, because it only gets executed once.
![]() | Building Graphics Applications on a PC | Running the MATLAB Compiler Outside MATLAB | ![]() |