MATLAB: Does the MATLAB Engine application fail to start based on an error about not being able to open a library

can'tdyldenginelibeng.dyliblibraryMATLABopenstart

Why does my MATLAB Engine application fail to start based on an error about not being able to open a library?
Type the following at the Matlab command prompt:
mex - f /Applications/MATLAB6p5/bin/engopts.sh engdemo.c
and this produces the executable 'engdemo'. However, I am getting the following run-time error:
dyld: ./engdemo can't open library: ../../bin/mac/libeng.dylib (No such file or directory, errno = 2)
Trace/BPT trap
The library is located in:
$(MATLAB)/extern/lib/mac

Best Answer

This error is due to an incorrect dynamic library path. For more information on setting your dynamic library path see the related solution.