C Standalone Application Target

Compiling the Application

This example takes an M-file, magicsquare.m, and creates a standalone C application, magicsquare.

  1. Copy the file magicsquare.m from

    matlabroot/extern/examples/compiler
    

    to your work directory.

  2. To compile the M-code, use

    mcc -mv magicsquare.m
    

    The -m option tells the MATLAB® Compiler™ product (mcc) to generate a C standalone application. The -v option (verbose) displays the compilation steps throughout the process and helps identify other useful information such as which third-party compiler is used and what environment variables are referenced.

    This command creates the standalone application called magicsquare and additional files. The Windows® platform appends the .exe extension to the name. See the table in Standalone Executable for the complete list of files created.

Testing the Application

These steps test your standalone application on your development machine.

  1. Update your path as follows:

    Windows®.  Add the following directory to your path.

    matlabroot\bin\win32

    UNIX®.  Add the following platform-specific directories to your dynamic library path.

    Linux®

    setenv LD_LIBRARY_PATH 
    	matlabroot/sys/os/glnx86: 
    	matlabroot/bin/glnx86: 
    	matlabroot/sys/java/jre/glnx86/jre1.6.0/lib/i386/native_threads: 
    	matlabroot/sys/java/jre/glnx86/jre1.6.0/lib/i386/server: 
    	matlabroot/sys/java/jre/glnx86/jre1.6.0/lib/i386:
    setenv XAPPLRESDIR matlabroot/X11/app-defaults
    

    Solaris™ 64

    setenv LD_LIBRARY_PATH 
    /usr/lib/lwp: 
    matlabroot/sys/os/sol64: 
    matlabroot/bin/sol64: 
    matlabroot/sys/java/jre/sol64/jre1.5.0/lib/sparcv9/native_threads: 
    matlabroot/sys/java/jre/sol64/jre1.5.0/lib/sparcv9/server: 
    matlabroot/sys/java/jre/sol64/jre1.5.0/lib/sparcv9: 
    setenv XAPPLRESDIR matlabroot/X11/app-defaults 
    

    Linux x86-64

    setenv LD_LIBRARY_PATH 
    	matlabroot/sys/os/glnxa64: 
    	matlabroot/bin/glnxa64: 
    	matlabroot/extern/lib/glnxa64:
    	matlabroot/sys/java/jre/glnxa64/jre1.6.0/lib/amd64/native_threads: 
    	matlabroot/sys/java/jre/glnxa64/jre1.6.0/lib/amd64/server: 
    	matlabroot/sys/java/jre/glnxa64/jre1.6.0/lib/amd64:
    setenv XAPPLRESDIR matlabroot/X11/app-defaults
    

    Mac OS® X

    setenv DYLD_LIBRARY_PATH 
    	matlabroot/bin/mac: 
    	matlabroot/sys/os/mac: 
    	/System/Library/Frameworks/JavaVM.framework/JavaVM: 
    	/System/Library/Frameworks/JavaVM.framework/Libraries
    setenv XAPPLRESDIR matlabroot/X11/app-defaults
    

    Intel® Mac® (Maci)

    setenv DYLD_LIBRARY_PATH 
      matlabroot/bin/maci: 
      matlabroot/sys/os/maci: 
      /System/Library/Frameworks/JavaVM.framework/JavaVM: 
      /System/Library/Frameworks/JavaVM.framework/Libraries 
    setenv XAPPLRESDIR matlabroot/X11/app-defaults 
    

  2. Run the standalone application from the system prompt (shell prompt on UNIX® or DOS prompt on Windows) by typing the application name.

    magicsquare.exe 4              (On Windows)
    magicsquare 4                  (On UNIX)
    

    The results are displayed as

    ans =
        16     2     3    13
         5    11    10     8
         9     7     6    12
         4    14    15     1
    

Deploying the Application

You can distribute a MATLAB Compiler generated standalone application to any target machine that has the same operating system as the machine on which the application was compiled.

For example, if you want to deploy an application to a Windows machine, you must use the MATLAB Compiler product to build the application on a Windows machine. If you want to deploy the same application to a UNIX machine, you must use the MATLAB Compiler product on the same UNIX platform and completely rebuild the application. To deploy an application to multiple platforms requires MATLAB® and MATLAB Compiler licenses on all the desired platforms.

Windows®

Gather and package the following files and distribute them to the deployment machine.

Component

Description

MCRInstaller.exe

Self-extracting MATLAB Compiler Runtime library utility; platform-dependent file that must correspond to the end user's platform.

magicsquare.ctf

Component Technology File archive; platform-dependent file that must correspond to the end user's platform

magicsquare

Application; magicsquare.exe for Windows

UNIX®

Distribute and package your standalone application on UNIX by packaging the following files and distributing them to the deployment machine.

Component

Description

MCRInstaller.bin

MATLAB Compiler Runtime library archive; platform-dependent file that must correspond to the end user's platform

unzip

Utility to unzip MCRInstaller.zip (optional). The target machine must have an unzip utility installed.

magicsquare.ctf

Component Technology File archive; platform-dependent file that must correspond to the end user's platform

magicsquare

Application

Running the Application

These steps describe the process that end users must follow to install and run the application on their machines.

Preparing Windows® Machines

  1. Install the MCR by running the MCR Installer in a directory. For example, run MCRInstaller.exe in C:\MCR. For more information on running the MCR Installer utility, see Working with the MCR.

  2. Copy the CTF archive and executable or library to your application root directory, for example, C:\approot.

  3. Add the following directory to your system path:

    <mcr_root>\<ver>\runtime\win32

Preparing UNIX® Machines

  1. Install the MCR by unzipping MCRInstaller.zip in a directory, for example, /home/<user>/MCR. You may choose any directory except matlabroot or any directory below matlabroot.

  2. Copy the CTF archive to your application root directory, for example, /home/<user>/approot.

  3. Add the following platform-specific directories to your dynamic library path.

Linux

setenv LD_LIBRARY_PATH 
	<mcr_root>/<ver>/runtime/glnx86: 
	<mcr_root>/<ver>/sys/os/glnx86: 
	<mcr_root>/<ver>/sys/java/jre/glnx86/jre1.6.0/lib/i386/native_threads: 
	<mcr_root>/<ver>/sys/java/jre/glnx86/jre1.6.0/lib/i386/server: 
	<mcr_root>/<ver>/sys/java/jre/glnx86/jre1.6.0/lib/i386:
setenv XAPPLRESDIR <mcr_root>/<ver>/X11/app-defaults

Solaris 64

setenv LD_LIBRARY_PATH 
/usr/lib/lwp: 
<mcr_root>/<ver>/runtime/sol64: 
<mcr_root>/<ver>/sys/os/sol64: 
<mcr_root>/<ver>/sys/java/jre/sol64/jre1.5.0/lib/sparcv9/native_threads: 
<mcr_root>/<ver>/sys/java/jre/sol64/jre1.5.0/lib/sparcv9/server: 
<mcr_root>/<ver>/sys/java/jre/sol64/jre1.5.0/lib/sparcv9: 
setenv XAPPLRESDIR <mcr_root>/<ver>/X11/app-defaults 

Linux x86-64

setenv LD_LIBRARY_PATH 
	<mcr_root>/<ver>/runtime/glnxa64: 
	<mcr_root>/<ver>/sys/os/glnxa64: 
	<mcr_root>/<ver>/sys/java/jre/glnxa64/jre1.6.0/lib/amd64/native_threads: 
	<mcr_root>/<ver>/sys/java/jre/glnxa64/jre1.6.0/lib/amd64/server: 
	<mcr_root>/<ver>/sys/java/jre/glnxa64/jre1.6.0/lib/amd64:
setenv XAPPLRESDIR <mcr_root>/<ver>/X11/app-defaults

Mac OS X

setenv DYLD_LIBRARY_PATH 
	<mcr_root>/<ver>/runtime/mac: 
	<mcr_root>/<ver>/sys/os/mac: 
	<mcr_root>/<ver>/bin/mac: 
	/System/Library/Frameworks/JavaVM.framework/JavaVM: 
	/System/Library/Frameworks/JavaVM.framework/Libraries
setenv XAPPLRESDIR <mcr_root>/<ver>/X11/app-defaults

Intel Mac (Maci)

setenv DYLD_LIBRARY_PATH 
   <mcr_root>/version/runtime/maci: 
   <mcr_root>/version/sys/os/maci: 
   <mcr_root>/version/bin/maci: 
   /System/Library/Frameworks/JavaVM.framework/JavaVM: 
   /System/Library/Frameworks/JavaVM.framework/Libraries 
setenv XAPPLRESDIR <mcr_root>/version/X11/app-defaults 

Executing the Application

Run the magicsquare standalone application from the system prompt and provide a number representing the size of the desired magic square, for example, 4.

magicsquare 4

The results are displayed as:

ans =
    16     2     3    13
     5    11    10     8
     9     7     6    12
     4    14    15     1

  


 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS