Technical Solutions
How do I compile and run a MATLAB Engine program on UNIX/Linux/Mac?
Date Last Modified: Friday, June 26, 2009
| Solution ID: |
|
1-1BSZR |
| Product: |
|
MATLAB |
| Reported in Release: |
|
R13 |
| Fixed in Release: |
|
R2006a+ |
| Platform: |
|
UNIX |
| Operating System: |
|
UNIX Any |
Subject:
How do I compile and run a MATLAB Engine program on UNIX/Linux/Mac?
Problem Description:
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.
Solution:
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 shell, enter
setenv 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:
http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_external/f40528.html
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
|