Main Content

Steps for Deployment with MATLAB Compiler

You can use MATLAB® Compiler™ and MATLAB Compiler SDK™ to package MATLAB files into deployable components that do not require MATLAB to run.

With MATLAB Compiler, you can create standalone applications, web apps, Microsoft® Excel® Add-ins, and MapReduce or Spark™ big data applications.

With MATLAB Compiler SDK, you can create C/C++ shared libraries, .NET assemblies, Java® classes, Python® packages, COM components, MATLAB Production Server™ deployable archives, Excel add-ins for MATLAB Production Server, and Docker® container-based microservices.

Write Deployable MATLAB Code

To package MATLAB scripts, functions, or class files to run outside of the MATLAB environment, you must first ensure the code is in a finished state and ready to be run by the end user. You can use functions such as isdeployed to separate code that must run before deployment. For example, in a deployed application, the MATLAB paths are fixed and cannot change, so use isdeployed to separate out code that modifies the path. For more information, see Write Deployable MATLAB Code.

In addition to MATLAB scripts, MEX files, and class files, you can include other types of files, such as data files, in the compiled artifact. For details, see Include and Access Files in Packaged Applications.

Package Code for Target

You can use the following options to package MATLAB code.

  • The compiler.build and compiler.package functions, which allow you to package MATLAB code at the command line

  • The deploytool compiler apps, which allow you to package MATLAB code using a graphical interface

  • The mcc function, which allows you to package MATLAB code at the command line and offers additional options to control the packaging process

For information on choosing which packaging method to use, see Choose Deployment Option.

During the packaging process, the compiler performs the following steps:

  1. Uses a dependency analysis function to include necessary supporting files. For more details, see Dependency Analysis Using MATLAB Compiler.

  2. Validates MEX-files. In particular, mexFunction entry points are verified. For more details about including MEX-files in packaged applications, see Include and Access Files in Packaged Applications.

  3. Creates a deployable archive from the input files and their dependencies. For more details, see About Deployable Archives.

  4. Generates target-specific wrapper code.

  5. Generates a target-specific binary package.

    For library targets such as C++ shared libraries, Java packages, or .NET assemblies, the compiler invokes the corresponding third-party compiler.

Distribute Files to Target Platform

Once you create a component, distribute either the application files or an installer that contains all of the resources required to run the application on the target platform. You can create an installer using a deploytool compiler app or using the compiler.package.installer function.

The installer created by compiler.package.installer installs your MATLAB Compiler generated artifacts, any generated sample code, and optionally the full MATLAB Runtime. To create a minimal MATLAB Runtime installer that can run one or more specific MATLAB Compiler applications, see compiler.runtime.customInstaller. (since R2024b)

If you create an installer containing the compiled artifacts and MATLAB Runtime, then MATLAB Runtime is installed along with the application or shared library. If you distribute files manually, ensure MATLAB Runtime is accessible from the target machine. For more information on distributing files, see Distribute MATLAB Compiler SDK Files to Application Developers.

Integrate Artifact with Target Language Application

If you use MATLAB Compiler SDK to package MATLAB functions for use in applications written in other programming languages, you must write application code in the target language that uses the packaged MATLAB functionality. For more details, see Integrate Artifact with Target Language Application (MATLAB Compiler SDK).

After integrating the artifact with your target language application and testing the application code against MATLAB Runtime, deploy the application along with all required files and dependencies to the end user machine.

Install MATLAB Runtime

MATLAB Runtime is a freely available set of shared libraries that enables you to run packaged MATLAB code without needing a licensed version of MATLAB. For details, see About MATLAB Runtime.

If you use an installer containing the compiled artifacts and MATLAB Runtime, then MATLAB Runtime is installed along with the application or shared library. If you distribute files manually, ensure MATLAB Runtime is accessible from the target machine at the same version or newer than the version of MATLAB used to compile the component.

You can run your deployed component on your development machine in MATLAB without needing MATLAB Runtime.

Limitations and Restrictions

You can package most MATLAB functionality that can be called directly from the command line. For a list of functions not supported by MATLAB Compiler, see Functions Not Supported for Compilation by MATLAB Compiler and MATLAB Compiler SDK.

Compiled applications can run only on the same platform on which they were developed, with some exceptions. For more details, see Limitations (MATLAB Compiler SDK).

See Also

| | |

Related Topics