Ensuring Multi-Platform Portability

Compiled MATLAB® code containing only MATLAB files are platform independent, as are .jar files. These files can be used out of the box on any platform providing that the platform has either MATLAB or the MATLAB Runtime installed.

However, if your compiled MATLAB code contains MEX-files, which are platform dependent, do the following:

  1. Compile your MEX-file once on each platform where you want to run your application.

    For example, if you are running on a Windows® machine, and you want to also run on the Linux® 64-bit platform, compile my_mex.c twice (once on a PC to get my_mex.mexw64 and then again on a Linux 64-bit machine to get my_mex.mexa64).

  2. Compile the package on one platform using the mcc command, using the -a flag to include the MEX-file compiled on the other platform(s). In the example above, run mcc on Windows and include the -a flag to include my_mex.mexa64. In this example, the mcc command would be:

    mcc -W 'java:mycomp,myclass' my_matlab_file.m -a my_mex.mexa64 

    Note

    In this example, it is not necessary to explicitly include my_mex.mexw64 (providing you are running on Windows). This example assumes that my_mex.mexw64 and my_mex.mexa64 reside in the same folder.

For example, if you are running on a Windows machine and you want to ensure portability of the generated package that invokes the yprimes.c file (from matlabroot\extern\examples\mex) on the Linux 64-bit platform, execute the following mcc command:

mcc -W 'java:mycomp,myclass' callyprime.m -a yprime.mexa64 
where callyprime.m can be a simple MATLAB function as follows:
function callyprime 
disp(yprime(1,1:4)); 
Ensure the 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:

  1. Run mcc with the -v option to list the names of the MEX-files.

  2. Obtain appropriate versions of these files from the version of MATLAB installed on your target operating system.

  3. Include these versions in the archive by running mcc with the -a option.

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 only run on that specific platform when deployed. For example, functionality from the Data Acquisition Toolbox™ only runs on Windows.

JAR files produced by MATLAB Compiler SDK™ are tested and qualified to run on platforms supported by MATLAB. See the Platform Roadmap for MATLAB for more information.