Deploy Add-Ons
MATLAB® deployment tools such as MATLAB Compiler™ and MATLAB Compiler SDK™ package MATLAB functions for deployment to environments external to the MATLAB desktop. These deployment tools can also package the proxy functions that MATLAB Production Server™ add-ons install to create deployable software components that require both the external environment and an active MATLAB Production Server instance.
For example, consider a deployable archive fractal.ctf that contains a
MATLAB function mandelbrot hosted on a MATLAB
Production Server instance.
You can install the fractal add-on on a client machine from the
fractal archive using MATLAB Client for MATLAB
Production Server. Installing the fractal add-on installs the proxy
mandelbrot function on your machine. Then, you can write a client program
in MATLAB that uses the proxy mandelbrot function.
You can also package the proxy mandelbrot function into a shared
library, for example, fractal.dll, using MATLAB
Compiler SDK. Then, you can write a C++ client program that uses
fractal.dll.
The following diagram shows the MATLAB client (in blue) and the C++ client (in green) calling the same proxy
mandlebrot function to communicate with the mandelbrot
function deployed to a MATLAB
Production Server instance.

The following examples show how to package installed proxy functions into a standalone
executable, a shared library, and a deployable archive. The examples use files in the
folder on your system. The support_package_root\toolbox\mps\matlabclient\demodemo folder contains the following folders:
fractal— ContainsmandelbrotandsnowflakeMATLAB functions. Themandelbrotfunction generates a Mandelbrot set and thesnowflakefunction generates the outline of a Koch snowflake. You package these MATLAB functions into a MATLAB Production Server deployable archive.mandelflake— Contains themandelflakeMATLAB function that displays the Mandelbrot set and the Koch snowflake. You package themandelflakefunction into a standalone executable.fractalViewer— Contains thetwoFractalsMATLAB function that displays the Mandelbrot set and the Koch snowflake based on input arguments that you specify. You package thetwoFractalsfunction into a shared library and a deployable archive.
Prerequisites
The examples require that you have the fractal
MATLAB
Production Server add-on available in your MATLAB session. The examples package the proxy functions from the
fractal add-on into a standalone executable, a shared library, and a
deployable archive. To make the fractal add-on available in MATLAB:
Package the
mandelbrotandsnowflakeMATLAB functions from the\demo\fractal\folder into a deployable archive calledfractalusing the Production Server Archive Compiler (MATLAB Compiler SDK) app. You must include a MATLAB function signature file when you create the archive. For more information about packaging archives, see Create Deployable Archive for MATLAB Production Server (MATLAB Compiler SDK).Deploy the
fractalarchive to a MATLAB Production Server instance. For more information about deploying the archive, see Deploy Archive to MATLAB Production Server.Confirm with the server administrator that the discovery service is enabled on the server. For more information, see Discovery Service.
Install the
fractaladd-on in your MATLAB desktop. For more information about installing add-ons, seeprodserver.addon.install. For a detailed example about installing MATLAB Production Server add-ons, see Execute Deployed MATLAB Functions.
You can verify that the fracatl add-on is available in your
MATLAB session by running prodserver.addon.availableAddOns. To test your installation of the
fractal add-on, you can run the example MATLAB function mandelflake that is in
\demo\mandelflake at the MATLAB command prompt.
The standalone executable and shared library require MATLAB Runtime. Install MATLAB Runtime on your machine if you have not already done so. For more information, see MATLAB Runtime.
Create Standalone Executables That Use Add-Ons
This example shows how to package a proxy function that a MATLAB Production Server add-on installs, into a standalone executable to invoke a MATLAB function hosted on a MATLAB Production Server instance. This example requires MATLAB Compiler. You can run standalone executables on computers that do not have MATLAB installed.
For this example, copy the contents of the
folder to a separate writable location on your system, for example, to a folder calledsupport_package_root\toolbox\mps\matlabclient\demo\mandelflakemandelflake.Navigate to the writable
mandelflakefolder from the MATLAB command prompt. Themandelflakefolder contains a MATLAB function calledmandelflake. Use themcc(MATLAB Compiler) command to create a standalone executable calledmandelflakefrom themandelflakeMATLAB function.>> cd mandelflake >> mcc -m mandelflake
This command produces an executable file
mandelflake.exeon a Windows® system.On Linux® and macOS, it produces an executable called
mandelflake.Run the executable at the system command prompt to display the Mandelbrot set and Koch snowflake.
C:\mandelflake> mandelflake
Two windows appear, one containing the Mandelbrot set and one displaying the Koch snowflake.
Create Shared Libraries or Software Components That Use Add-Ons
This example shows how to package a proxy function that a MATLAB Production Server add-on installs, into a shared library, then use the shared library in a C++ client to invoke a MATLAB function hosted on a MATLAB Production Server instance. This example requires MATLAB Compiler SDK and a supported C++ compiler. For a list of supported C++ compilers, see Supported and Compatible Compilers. MATLAB Compiler SDK creates software components, such as shared libraries, from MATLAB functions.
For this example, copy the contents of the
folder to a separate writable location on your system, for example, to a folder calledsupport_package_root\toolbox\mps\matlabclient\demo\fractalViewerfractalViewer. ThefractalViewerfolder contains the following:A MATLAB function
twoFractalsthat displays images of the Mandelbrot set and the Koch snowflake based on the input arguments to the functionA C++ application
fractalViewerthat invokes thetwoFractalsfunction with the required input arguments
Navigate to the writable
fractalViewerfolder from the MATLAB command prompt. Use themcc(MATLAB Compiler) command to create a shared library calledtwoFractals.libfrom thetwoFractals.mMATLAB function.>> cd fractalViewer >> mcc -W cpplib:twoFractals twoFractals.m
The
twoFractalsshared library requires a client to utilize its public interface. Use thembuild(MATLAB Compiler SDK) function to compile and link thefractalViewerC++ application against thetwoFractalsshared library. ThefractalViewerC++ application invokes thetwoFractalsfunction with the appropriate inputs.>> mbuild fractalViewer.cpp twoFractals.lib
This command produces an executable file
fractalViewer.exeand a shared librarytwoFractals.dllon a Windows system.On Linux, it produces an executable
twoFractals.soand a shared libraryfractalViewer. On macOS, it produces an executabletwoFractals.dyliband a shared libraryfractalViewer.Run the
fractalViewerexecutable at the system command prompt to display the Mandelbrot set and Koch snowflake.C:\fractalViewer> fractalViewer
Two windows appear, one containing the Mandelbrot set and one displaying the Koch snowflake.
Create Deployable Archives That Use Add-Ons
This example shows how to package a proxy function that is in one MATLAB Production Server add-on into a MATLAB Production Server archive, from which you can install a second MATLAB Production Server add-on. In this case, the proxy functions of the second add-on call the proxy functions of the first add-on, which in turn call the actual functions (functions hosted on the first MATLAB Production Server instance) of the first add-on. With this feature, you can chain together multiple MATLAB Production Server archives. However, longer chains require more network resources and run more slowly. Application access control is not supported for deployed archives that contain the add-on proxy functions.
This example requires MATLAB Compiler SDK.
For this example, copy the contents of the
folder to a separate writable location on your system, for example, to a folder calledsupport_package_root\toolbox\mps\matlabclient\demo\fractalViewerfractalViewer. ThefractalViewerfolder contains a MATLAB functiontwoFractalsthat displays images of the Mandelbrot set and the Koch snowflake.Create a MATLAB function signature file
twoFractalsFunctionSignatures.jsonin the writablefractalViewerfolder. You require a MATLAB function signature file when you create a deployable archive of thetwoFractalsfunction. For more information, see MATLAB Function Signatures in JSON. A sample MATLAB function signature file follows.Navigate to the writable
fractalViewerfolder from the MATLAB command prompt. Use themcc(MATLAB Compiler) command to create a deployable archivetwoFractal.ctffrom thetwoFractals.mMATLAB function.>> cd fractalViewer >> mcc('-W','CTF:twoFractals,DISCOVERY:twoFractalsFunctionSignatures.json','-U','twoFractals.m')
Copy the resulting archive,
twoFractals.ctf, to theauto_deployfolder of a MATLAB Production Server instance.Then, install the
twoFractalsMATLAB Production Server add-on. For example, if your MATLAB Production Server instance has the network addresslocalhost:9910, use the following command:>> prodserver.addon.install('twoFractals','localhost',9910)
Finally, invoke the
twoFractalsproxy function:Two windows appear, one containing the Mandelbrot set and one displaying the Koch snowflake.>> twoFractals(300,600,5)
