Skip to Main Content Skip to Search
Product Documentation

Creating a Standalone Application or Shared Library From MATLAB Code

The MATLAB programmer performs the following tasks.

MATLAB Programmer

RoleKnowledge BaseResponsibilities

MATLAB programmer
  • MATLAB expert

  • No IT experience

  • No access to IT systems

  • Develops models; implements in MATLAB

  • Serves as tool builder

  • Uses tools to create a component that is used by the C or C++ developer

Key Tasks for the MATLAB Programmer

TaskReference
Test the MATLAB code to ensure that it is suitable for deployment.magicsquare Testing
Create a standalone application or shared library by running the deploytool.Deployable Standalone or Shared Library Creation
Run the Packaging Tool to bundle your standalone application or shared library with any additional files you select.Packaging (Optional)
Copy the output from the Packaging Tool (the distrib folder) and hand off to the C/C++ developer.Package Copying (Optional)

magicsquare Testing

In this example, you test a MATLAB file (magicsquare.m) containing the predefined MATLAB function magic, in order to have a baseline to compare to the results of the function when it is deployed as a standalone application or shared library.

  1. Using MATLAB, locate and open magicsquare.m. This file should appear similar to the following:

    function m = magicsquare(n)
    %MAGICSQUARE generates a magic square matrix of the size
    % specified by the input parameter n.
    
    % Copyright 2003-2012 The MathWorks, Inc.
    
    if ischar(n)
        n=str2num(n);
    end
    m = magic(n);
    
  2. At the MATLAB command prompt, enter magicsquare(5), and view the results. The output appears as follows:

    17 24  1  8 15
    23  5  7 14 16
     4  6 13 20 22
    10 12 19 21  3
    11 18 25  2  9

For More Information

If you want to...See...
  • Perform basic MATLAB Programmer tasks

  • Understand how the deployment products process your MATLAB functions

  • Understand how the deployment products work together

  • Explore guidelines about writing deployable MATLAB code

MATLAB Code Deployment

Deployable Standalone or Shared Library Creation

You create a deployable standalone application or shared library by using the Deployment Tool GUI to build a wrapper. This wrapper encloses the sample MATLAB code discussed in magicsquare Testing.

Using MATLAB Compiler, you have the choice to compile your MATLAB code to these four targets:

MATLAB Compiler Supported Compilation Targets

Compilation TargetFor information about when to compile to this target....
Standalone ApplicationWhen to Create a Standalone Application
Windows Console ApplicationWhen to Create a Standalone Application
What's the Difference Between a Windows Standalone Application and a Console/Standalone Application?
C Shared LibraryWhen to Create a Shared Library
C Shared Libraries
C++ Shared LibraryWhen to Create a Shared Library
C++ Shared Libraries

Use the following information when creating your component as you work through this example:

Project NameMagicExample
File to compilemagicsquare.m

  1. Start MATLAB, if you have not done so already.

  2. Type deploytool at the command prompt, and press Enter. The Deployment Project dialog box opens.

    The Deployment Project Dialog Box

  3. Create a deployment project using the Deployment Project dialog box:

    1. Type the name of your project, in the Name field.

    2. Enter the location of the project in the Location field. Alternately, navigate to the location.

    3. Select the target for the deployment project from the Type drop-down menu.

        Note   Windows standalone targets differ from conventional standalone targets. A Windows standalone application produces no output to the MS-DOS window. Consider this difference when selecting between the targets in accordance with your user requirements.

    4. Click OK.

      Tip   You can inspect the values in the Settings dialog before building your project. To do so, click the Action icon ( ) on the toolbar, and then click Settings. Verify where your src and distrib folders will be created because you will need to reference these folders later.

  4. On the Build tab:

    • If you are building a standalone target, click Add main file to open the Add Files dialog box..

      Click Open to select the file or files.

        Note   In this context, main file refers to the primary MATLAB file you want to deploy. It does not refer to the main module in a C or C++ program.

    • If you are building a shared library target, click Add files to open the Add Files dialog box.

      Click Open to select the file or files.

    • You may optionally add supporting files. For examples of these files, see the deploytool Help. To add these files, in the Shared Resources and Helper Files area:

      1. Click Add files/directories

      2. Click Open to select the file or files.

  5. When you complete your changes, click the Build button ( ). When the build finishes, click Close to dismiss the dialog box.

What Gets Built?

After you build your standalone application or shared library with the Deployment Tool, you have the following in the src and distrib subdirectories of your project directory:

These Subdirectories of the Project Directory:Contain these files:
srcIf you built a standalone application:
  • applicationName.exe — the executable application.

  • readme.txt containing important information about how to use this built component.

  • LOG file listing functions that were not compiled or included in this build.


If you built a shared library:

distribIf you built a standalone application:
  • applicationName.exe — the executable application.

  • readme.txt containing important information about how to use this built component.


If you built a shared library:

Packaging (Optional)

Packaging is bundling the standalone application or shared libraries with additional files for end users. Perform this step using the Package tab of deploytool. Alternately, copy the contents of the distrib folder and the MCR Installer to a local folder of your choice.

  1. On the Package tab, add the MATLAB Compiler Runtime (MCR). To do so, click Add MCR, and choose one of the two options described in the following table.

    OptionWhat Does This Option Do?When Should I Use This Option?
    Embed the MCR in the packageThis option physically copies the MCR Installer file into the package you create.
    • You have a limited number of end users who deploy a small number of applications at sporadic intervals

    • Your users have no intranet/network access

    • Resources such as disk space, performance, and processing time are not significant concerns

        Note   Distributing the MCR Installer with each application requires more resources.

    Invoke the MCR from a network locationThis option lets you add a link to an MCR Installer residing on a local area network, allowing you to invoke the installer over the network, as opposed to copying the installer physically into the deployable package.
    This option sets up a script to install the MCR from a specified network location, saving time and resources when deploying applications.
    • You have a large number of end users who deploy applications frequently

    • Your users have intranet/network access

    • Resources such as disk space, performance, and processing time are significant concerns for your organization

    If you choose this option, modify the location of the MCR Installer, if needed. To do so, select the Preferences link in this dialog box, or change the Compiler option in your MATLAB Preferences.

      Caution   Before selecting this option, consult with your network or systems administrator. Your administrator may already have selected a network location from which to run the MCR Installer.

    For more information about the role the MCR plays in the deployment process, see Distribute MATLAB Code Using the MATLAB Compiler Runtime (MCR).

  2. Next, add others files you feel may be useful to end users. To package additional files or folders, click Add file/directories, select the file or folder you want to package, and click Open.

  3. In the Deployment Tool, click the Packaging button ( ).

  4. For Windows, the package is a self-extracting executable. On platforms other than Windows, the package is delivered as a .zip file. Verify that the contents of the distrib folder contains the files you specified.

Package Copying (Optional)

Copy the package that you created from the distrib folder to the local folder of your choice or send them to the C/C++ programmer, if applicable.

  


Free MATLAB Compiler Interactive Kit

Learn how to build standalone executables and C/C++ shared libraries from MATLAB code.


Get free kit

Trials Available

Try the latest version of MATLAB Compiler.


Get trial software
 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS