Integrate Artifact with Target Language Application
MATLAB® Compiler SDK™ allows you to package MATLAB functions for use in applications written in other programming languages. For an overview on packaging and deploying MATLAB code, see Steps for Deployment with MATLAB Compiler.
Several deployment targets are available with MATLAB Compiler SDK.
.NET
C/C++
Python®
Java®
COM
MATLAB Production Server™
Docker®
Meet Requirements and Prepare Development Environment
Before you begin to develop code in your target language, you must meet the requirements and set up your development environment. This preparation involves installing the necessary software tools, including a code editor or integrated development environment (IDE). For some targets, such as .NET or Java, the compiler invokes the corresponding third-party compiler to create the artifact, so you must set up your development environment to work with the target language.
For general information about MATLAB Compiler SDK requirements, see Supported Hardware and Software. For specific requirements and development guidelines, see the documentation for your target language.
Choose API for .NET or C++
For .NET and C++ applications, MATLAB Compiler SDK provides two options to handle data exchange between the application and deployed MATLAB functions. Before packaging a .NET assembly or C++ shared library, you must select the API that best matches the requirements for your project.
The .NET target has the following API options.
MWArray
API — legacy option that usesMWArray
classes for arguments and return valuesMATLAB Data API — modern option that uses a mapping between MATLAB and target language data types
For more details, see Choose .NET Deployment Option.
The C++ target has the following API options.
mwArray
API — legacy option that usesmxArray
classes for arguments and return valuesMATLAB Data API — modern option that uses a mapping between MATLAB and target language data types
For more details, see Choose C++ Deployment Option.
Package Code for Target
You can use the following options to package MATLAB code.
The
compiler.build
andcompiler.package
functions, 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
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 which packaging method to use, see Choose Deployment Option.
(Optional) Generate Sample Application Code
During packaging, MATLAB Compiler SDK can generate C++, .NET, Java, or Python code that demonstrates how to call your MATLAB exported function in the target language. You can use this sample code to test the compiled artifact or as a base to implement your own application. For more details, see Create Sample Code to Call Exported Function.
For an example on using application code generated by MATLAB Compiler SDK, see Generate Python Package and Build Python Application.
Write Application Code in Target Language
After packaging MATLAB code, distribute the generated files to the development environment. For information on which files to distribute, see Distribute MATLAB Compiler SDK Files to Application Developers. Then, write application code in the target language that uses the packaged MATLAB functionality.
For deployment to MATLAB Production Server or to Docker as a microservice, access the packaged MATLAB functionality using a client application that sends and receives data using HTTP requests. For details, see the documentation for your deployment target.
For other target languages, application code typically uses the following structure.
Includes the compiled MATLAB artifact
Includes header files or other required libraries, such as the Python
matlab
packageInitializes MATLAB Runtime, if necessary
Uses a
try
-catch
block to handle exceptionsInitializes an instance of the compiled artifact as an object
Creates data objects for each input argument as needed
Calls the MATLAB function using the artifact object instance
Prints any output
Terminates the object instances and MATLAB Runtime
For specific implementation details, see the documentation for your target language.
Deploy Application and MATLAB Runtime
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 for deployment.
To generate an installer that installs your compiled artifact along with MATLAB Runtime, package your code using a Compiler app or use a function such as
compiler.package.installer
or compiler.runtime.customInstaller
.
By default, installers only contain files generated by MATLAB
Compiler SDK, including sample code, and any additional files added during packaging.
Installers do not include any application code written after packaging. Some targets,
such as .NET, C++, and Java, require you to compile application code into an executable bundle after
building the component. To ensure end users can run the executable, you can include a
target language application in an installer using the AdditionalFiles
option of the compiler.package.installer
function.
As an alternative to using an installer, you can distribute generated files manually to the end user. For details, see Distribute MATLAB Compiler SDK Files to Application Developers. In order to run the application, the target machine must have access to MATLAB Runtime that matches the version of MATLAB used to compile the component, at the same update level or newer. For details, see About MATLAB Runtime.
See Also
compiler.build.Results
| mcc
| compiler.package.installer
| compiler.runtime.customInstaller