How to generate an executable on one Linux machine and run it on another

For MATLAB Compiler Version 4.6

The instructions for generating a stand-alone executable in the following is for MATLAB 7.4 (or MATLAB 2007a), with the compiler at version 4.6. Different versions of MATLAB may require somewhat different procedures for creating standalone executables. Make sure to use the instructions that correspond to the compiler available on the machine you intend to use to generate standalone executables.

Here is a way to find out what version compiler you have:

>> ver    % this produces a list of toolboxes (including the compiler)
          % and their version numbers
  1. Create a stand-alone executable on a Linux machine:
    1. Create a new directory and copy all required files (in this case: myexample.m, filea.m, and fileb.m) into it.
      >> mcc -m myexample filea fileb  % compile myexample.m filea.m fileb.m
      

      The mcc command above compiles myexample.m, filea.m, and fileb.m into an myexample executable, along with a bunch of additional files and a directory. If you want to run the stand-alone executable on this same machine (on which you have generated the stand-alone), you can skip to the “Run the stand-alone executable on a linux machine” section.

    2. Zip the entire directory for sending to the target (Linux) machine.
      • Compress the entire dir into a zip file to send to the (target) machine you intend to run jobs on.
      • Generate a MCRInstaller.zip file by running a MATLAB-provided buildmcr script at the MATLAB prompt. By default, this command puts MCRInstaller.zip in $MATLAB/toolbox/compiler/deploy. To create it in another directory (for instance, the current directory), you can specify the destination directory as an input to buildmcr. For example,
        >> buildmcr('.')  % create MCRInstaller.zip in the current dir
        
  2. Preprocessing on the target Linux machine
    • copy the code zip-file into a dir of choice.
    • Unzip the zip-file to extract myexample, etc.
    • Install the MCR by unzipping MCRInstaller.zip in, say, /project/matlab/matlab-2007a/MCR
  3. Run the stand-alone executable on another Linux machine

    If you generate the stand-alone exec on one Linux machine and run it on another Linux machine which has no MATLAB, then this is the run procedure:

    target-machine % run_myexample.sh /project/matlab/matlab-2007a/MCR/v76 
    > myexample.out
    

In connection with the compiler, MATLAB 7 provides a new utility called ISDEPLOYED. Here is the description, according to the MATLAB help file:

ISDEPLOYED tests if the code is running in deployed mode or MATLAB mode
   X = ISDEPLOYED returns true when the function is being run in deployed
   mode and false if it is being run within MATLAB environment.

This utility lets you know in what mode (MATLAB or standalone) the code is running. This is quite useful. In older versions, the compiler does not support GUI of toolboxes in a standalone. In the interests of maintaining a single source file for both the MATLAB and standalone modes, you could use ISDEPLOYED to determine at runtime whether to branch into the GUI section of the code. Other similar situations that depend on whether the job runs in the MATLAB or standalone modes may also warrant the use of ISDEPLOYED.

Source: MATLAB 7.4 documentation on MATLAB Compiler.

unk

unk unk unk