MATLAB: How to compile and run a MATLAB Engine program on UNIX/Linux/Mac

compileengdemoengdemo.cengineexecutelinuxmacMATLABosxprogramrununix

I have completed the steps in the External Interfaces manual but I am having difficulty compiling and running my Engine program. I would like step-by-step instructions on how to achieve this.

Best Answer

This enhancement has been incorporated in Release 2006b (R2006b). For previous product releases, read below for any possible workarounds:
To run an Engine application, you must set the path and the dynamic library path on your machine appropriately.
Perform the following steps:
1. To add MATLAB to the path environment variable:
On a bash shell, enter
export PATH=$PATH:(<matlabroot>/bin)
On a csh / tcsh shell, enter
set path = ($path <matlabroot>/bin)
where <matlabroot> is the path where MATLAB is installed and can found by entering
matlabroot
at the MATLAB Command Prompt.
2. On MATLAB 6.5(R13) Set the runtime library path environment variable LD_LIBRARY_PATH to:
<matlabroot>/extern/lib/<arch>:<matlabroot>/sys/os/<arch>:$LD_LIBRARY_PATH
On MATLAB 7.0(R14) and later set the runtime library path environment variable LD_LIBRARY_PATH to:
<matlabroot>/bin/<arch>:<matlabroot>/sys/os/<arch>:$LD_LIBRARY_PATH
Where <matlabroot> is the path to your MATLAB installation, and <arch> is the proper architecture/OS directory such as glnx86 if you are using x86 Linux.
Some UNIX operating systems use SHLIB_PATH or DYLD_LIBRARY_PATH instead of LD_LIBRARY_PATH, and therefore you may need to set them instead of LD_LIBRARY_PATH. For more details, and to see which one you should set, see the following URL:
3. Start MATLAB.
4. Compile and link the engdemo.c example:
mex -f <matlabroot>/bin/engopts.sh <pathname>/engdemo.c
where <pathname> specifies the complete path to the specified file.
5. Exit MATLAB.
6. From your shell prompt, execute:
<pathname>/engdemo