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
During the packaging process, the compiler performs the following steps:
Uses a dependency analysis function to include necessary supporting files. For more details, see Dependency Analysis Using MATLAB Compiler.
Validates MEX-files. In particular,
mexFunctionentry points are verified. For more details about including MEX-files in packaged applications, see Include and Access Files in Packaged Applications.Creates a deployable archive from the input files and their dependencies. For more details, see About Deployable Archives.
Generates target-specific wrapper code.
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.
You can use the following options to package MATLAB code.
The
compiler.buildandcompiler.packagefunctions, which allow you to package MATLAB code at the command lineThe compiler apps, which allow you to package MATLAB code using a graphical interface
The
mccfunction, which allows you to package MATLAB code at the command line and offers additional options to control the packaging process
For more information on these packaging methods, see Choose Deployment Option.
Test Artifacts Before Deployment
You can test artifacts generated by MATLAB Compiler and MATLAB Compiler SDK using a MATLAB installation instead of MATLAB Runtime. Typically, testing is performed with the same MATLAB installation used to generate the artifact. The version of MATLAB used for testing must match the version used to create the artifact. For more information on testing before deployment, see Set MATLAB Library Paths for Testing Deployed Applications.
Once testing is successful, you can transfer the artifact to a production environment and run it using MATLAB Runtime.
Distribute Files to Target Platform
Once you create a component, you can either distribute the application files manually or distribute an installer that contains all of the resources required to run the application on the target platform.
Distribute Application Installer
You can create an application installer using a compiler app or using the
compiler.package.installer function.
Installers created by MATLAB
Compiler include your generated artifacts, any generated sample code, and
optionally the MATLAB Runtime libraries required to run the specified application.
To create a minimal MATLAB Runtime installer that can run one or more specific MATLAB
Compiler applications, see compiler.runtime.customInstaller. (since R2024b)
To create installers using compiler.package.installer or compiler.runtime.customInstaller that include MATLAB Runtime, you must download the full MATLAB Runtime installer at the same version and update level as
the version of MATLAB used to create them. Then, specify the installer location in
Settings under MATLAB Compiler. You
can use the compiler.runtime.download function to obtain the MATLAB Runtime installer at the same release and update level as your MATLAB installation.
Distribute Files Manually
For MATLAB Compiler targets, you can distribute application files or the deployable archive directly for deployment. 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.
For information on which files to distribute to application developers for MATLAB Compiler SDK targets, see Distribute MATLAB Compiler SDK Files to Application Developers. After integrating the artifact with your target language application and testing the application code against MATLAB Runtime, distribute the application along with all required files and dependencies to the end user machine.
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, such as .NET or Python, you must write application code in the target language that calls the packaged MATLAB functionality. For more details, see Integrate Artifact with Target Language Application (MATLAB Compiler SDK).
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 more 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 test 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 with some exceptions, such as prebuilt graphical user interfaces. For more details, see Limitations for MATLAB Compiler (MATLAB Compiler SDK).
Compiled applications can run only on the same platform on which they were developed, with some exceptions. For information on best practices for multiplatform development, see Ensure Multiplatform Portability for Compiled Applications.
See Also
compiler.build.Results | compiler.package.installer | compiler.runtime.customInstaller | mcc