MATLAB: How to run the application compiled on a MAC using the MATLAB Compiler outside of MATLAB without manually setting the environment variables

#dtaksmcompilerdyld_library_pathexecutelibmwmclmcrrtmacMATLAB Compiler

I am compiling an application using the MCC command on Mac OS. When I try to run the compiled executable outside MATLAB, on my development machine, I receive the error message:
dyld: Library not loaded: @loader_path/libmwmclmcrrt.7.7.dylib
Reason: image not found
Trace/BPT trap
I know that this is probably due to not setting the DYLD_LIBRARY_PATH variable. I would like to know if there is an easy way to set these variables and run the application.

Best Answer

Instead of using the EXPORT command either manually, or within a script to set the environment variables, try the following command at your shell prompt:
./run_myapp.sh $MATLABROOT
This command automatically adds environment variables to the path, and executes the application.
Here, $MATLABROOT refers to the root directory where MATLAB is installed and can be found by typing
MATLABROOT
at MATLAB prompt. For example,
/Applications/Development/MATLAB_R2007b can be the matlabroot directory in a machine.
Note that run_myapp.sh is the shell file that is generated when you compile your application using the mcc command. For example, if I compile myapp.m using the following command:
mcc -m myapp.m
it generates a set of files, one of which is run_myapp.sh.
Note that you can also run the application on a deployment machine where MCR is installed in the following way:
./run_myapp.sh <mcrroot>
Here <mcrroot> refers to the root directory where MCR is installed