| Products & Services | Industries | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → MATLAB Compiler |
| Contents | Index |
| Learn more about MATLAB Compiler |
| On this page… |
|---|
This example takes an M-file, magicsquare.m, and creates a standalone C application, magicsquare.
Copy the file magicsquare.m from
matlabroot/extern/examples/compiler
to your work folder.
mcc -mv magicsquare.m
The -m option tells MATLAB Compiler (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.
These steps test your standalone application on your development machine.
Note Testing your application on your development machine is an important step to help ensure that your application is compilable. To verify that your application compiled properly, you must test all functionality that is available with the application. If you receive an error message similar to Undefined function or Attempt to execute script script_name as a function, it is likely that the application will not run properly on deployment machines. Most likely, your CTF archive is missing some necessary functions. Use -a to add the missing functions to the archive and recompile your code. |
Update your path as described in UNIX Settings for Development and Testing
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) magicsquare.app/Contents/MacOS/magicsquare (On Maci64)
The results are:
ans =
16 2 3 13
5 11 10 8
9 7 6 12
4 14 15 1
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 MATLAB Compiler to build the application on a Windows machine. If you want to deploy the same application to a UNIX machine, you must use MATLAB Compiler 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.
Note MCRInstaller.exe has obsoleted the need for the function buildmcr or the creation of MCRInstaller.zip. See Replacement of MCRInstaller.zip and BUILDMCR Functionality for more details including complete file paths to all install programs. |
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 | Application; magicsquare.exe for Windows |
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 |
magicsquare | Application |
Distribute and package your standalone application on 64-bit Macintosh by copying, tarring, or zipping as described in the following table.
Component | Description |
|---|---|
MCRInstaller.bin | MATLAB Compiler Runtime library archive; platform-dependent file that must correspond to the end user's platform |
magicsquare | Application |
magicsquare.app | Application bundle Assuming foo is a folder within your current folder:
|
These steps describe the process that end users must follow to install and run the application on their machines.
Install the MCR by running the MCRInstaller in a folder. For example, run MCRInstaller.exe in C:\MCR. For more information on running the MCR Installer utility, seeWorking with the MCR and Replacement of MCRInstaller.zip and BUILDMCR Functionality.
See Path Modifications Required for Accessibility for information on setting your path.
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
Note Input arguments you pass to and from a system prompt are treated as string input and you need to consider that in your application. For more information, see Passing Arguments to and from a Standalone Application. |
Note Before executing your MATLAB Compiler generated executable, set the LD_PRELOAD environment variable to /lib/libgcc_s.so.1. |
Executing the Application on 64-Bit Macintosh (Maci64). For 64-bit Macintosh, you run the application through the bundle:
magicsquare.app/Contents/MacOS/magicsquare
![]() | Introduction | Coding with M-Files Only | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |