Ensure Multiplatform Portability for Compiled Applications
Compiled MATLAB® code that contains only MATLAB files is platform independent, with some exceptions. You can run these files on any platform provided that the platform has either MATLAB or MATLAB Runtime installed. For more information on MATLAB Runtime, see About MATLAB Runtime.
The following components can only run on the same platform on which they were packaged:
Components that contain platform-specific files, unless you also include files for the additional platforms and specify the additional platforms using
mcc
with the-A
optionStandalone applications
Excel® add-ins and COM components, which can only run on Windows®
Docker® and microservice Docker images, which can only run in Linux® containers
C++ libraries compiled using the
mwArray
API.NET assemblies, except those compiled using .NET 6.0 or .NET Core
Deployable archives compiled for MATLAB Production Server™ that include operating system-specific dependencies or content, such as MEX files or Simulink® simulations
Simulink Compiler™ artifacts
MEX Files
If your compiled MATLAB code contains MEX files which are platform dependent, you can do the
following to allow them to run on other platforms. For this example, use the file
yprime.c
located in
.matlabroot
\extern\examples\mex
Compile your MEX file once on each platform where you want to run your application.
For example, if you want to run the application on the Windows 64-bit platform as well as the Linux 64-bit platform, compile
yprime.c
twice: once on a PC to getyprime.mexw64
and then again on a Linux 64-bit machine to getyprime.mexa64
.Create a simple MATLAB function named
callyprime.m
that callsyprime
.function callyprime disp(yprime(1,1:4));
Compile the package on one platform and use the
-a
option ofmcc
or theAdditionalFiles
option of acompiler.build
function to include the MEX file compiled on the other platform(s). Ensure that the Linux MEX file is in the same folder as the Windows MEX file.For example, if you are creating a Java® package on a Windows machine and you want to ensure the package can run on the Linux 64-bit platform, include the Linux MEX file
yprime.mexa64
.It is not necessary to explicitly include themcc -W 'java:myComp,myClass' callyprime.m -a yprime.mexa64
glnxa64
architecture here using-A
, as the dependency analysis process will detect the Linux MEX file and enable the platform.
Tip
If you are unsure if your application contains MEX files, do the following:
Run
mcc
with the-v
option to list the names of the MEX files, or enable theVerbose
option in acompiler.build
function.Obtain appropriate versions of these files from the version of MATLAB installed on your target operating system.
Include these versions in the archive by running
mcc
with the-a
option, or use theAdditionalFiles
options in acompiler.build
function.
MATLAB Toolboxes
Toolbox functionality that runs seamlessly across platforms when executed from within the MATLAB desktop environment will continue to run seamlessly across platforms when deployed. However, if a particular toolbox functionality is designed to run on a specific platform, then that functionality will run only on that specific platform when deployed. For example, functionality from the Data Acquisition Toolbox™ runs only on Windows.
Java JAR Files
Java JAR files are platform independent. However, if you add operating
system-specific dependencies or content to your package, such as MEX files or
Simulink simulations, the generated archive is limited to the compatible system.
You can override the restriction using mcc
with the -A
option.
JAR files produced by MATLAB Compiler SDK™ are tested and qualified to run on platforms supported by MATLAB. For more information, see the Platform Roadmap for MATLAB.
Web Apps
In most cases, you can generate a web app archive (.ctf
file) on
one platform and deploy to a server running on any other supported platform. Unless you
add operating system-specific dependencies or content, such as MEX files or Simulink simulations to your applications, the generated archives are
platform-independent.