2

I'm trying to build and run the Matlab Engine example "engdemo.c" using the instructions from Mathworks. When I try to run it with the command !./engdemo, I'm getting the following error:

matlab: Command not found.
Can't start MATLAB engine

I have not found a solution to this in other relevant StackOverflow posts (e.g. matlab engine “Can't start MATLAB engine" or How solve the “Can't start MATLAB engine” command? [closed])

I have csh installed at /bin/csh (checked this by typing which csh).

I have Matlab on my PATH variable, and I have set the DYLD_LIBRARY_PATH variable according to the Mathworks instructions for Mac OSX. Here are the lines I have included in my .bash_profile to set these environment variables:

# Settings for Matlab Engine using Apple XCode
export PATH=$PATH:/Applications/MATLAB_R2014a.app/bin
export PATH=$PATH:/Applications/MATLAB_R2014a.app/bin/maci64
export DYLD_LIBRARY_PATH=/Applications/MATLAB_R2014a.app/bin/maci64:/Applications/MATLAB_R2014a.app/sys/os/maci64:$DYLD_LIBRARY_PATH

Ultimately I would like to build a C program that uses Matlab scripts (ideally building with XCode), but it's frustrating to have trouble even getting the demo to work.

Community
  • 1
  • 1
Eric Miller
  • 110
  • 7

1 Answers1

0

I got it to work using these instructions from Mathworks. The key difference is the way I compiled engdemo.c with mex. Before I was using mex -client engine engdemo.c (see above), but I would get errors when trying to run the demo from either the Matlab prompt or from my shell.

Following that article, I changed to compiling with the following: mex -f /Applications/MATLAB_R2014a.app/bin/engopts.sh ./engdemo.c. At first this threw an error saying that it couldn't find SDK "macosx10.7" (note that I'm using OSX 10.9). I looked in engopts.sh and found a lot of references to macosx10.7.

Following this article, I edited engopts.sh by changing all references to macosx10.7 to macosx10.8. (Note that even though I have osx10.9, I also have the 10.8 SDK, which you can see by typing findxcode-select -print-path-name MacOSX10.8.sdk. I decided to use 10.8 because in that article someone said that other things broke when they used 10.9, but I have not checked this myself yet.)

After making these changes, I re-ran mex -f /Applications/MATLAB_R2014a.app/bin/engopts.sh ./engdemo.c, and it worked. Running ./engdemo from the shell ran the program successfully. This still seems very hackish to me.

Eric Miller
  • 110
  • 7