Ensure Multiplatform Portability for Java
Compiled MATLAB® code containing only MATLAB files are platform independent, as are Java®
.jar
files. You can use these files on any platform, provided that the
platform has either MATLAB or MATLAB Runtime installed. However, if your compiled MATLAB code contains MEX files, which are platform dependent, do the
following:
Compile your MEX file once on each platform where you want to run your application.
For example, if you are running the application on a Windows® machine, and you want it to run on the Linux® 64-bit platform, compile
twice, once on a PC to getmy_mex
.c
and then again on a Linux 64-bit machine to getmy_mex
.mexw64
.my_mex
.mexa64Compile the package on one platform using the
-a
flag ofmcc
or theAdditionalFiles
option in acompiler.build
function to include the MEX file compiled on the other platform(s).In the case above, you run
mcc
on Windows and include the-a
flag to include
. It is not necessary to explicitly includemy_mex
.mexa64
. In this step , themy_mex
.mexw64mcc
command would be:mcc -W 'java:mycomp,myclass' my_matlab_file.m -a my_mex.mexa64
For example, if you are running
mcc
on a Windows machine and you want to ensure portability of the generated package that invokes theyprime.c
file (from
) on the Linux 64-bit platform, execute the followingmatlabroot
\extern\examples\mexmcc
command:mcc -W 'java:mycomp,myclass' callyprime.m -a yprime.mexa64
callyprime.m
can be a simple MATLAB function, as follows:Ensure that thefunction callyprime disp(yprime(1,1:4));
yprime.mexa64
file is in the same folder as your Windows MEX file.
Tip
If you are unsure if your JAR file 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.
Caution
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.
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.