matlabexecutablemcc

mcc producing an unresponsive executable


I am trying to compile a Matlab function using the mcc function. My function writes a line of text to a file.

function hello()
    ofid = fopen('hello.txt','w');
    fprintf(ofid, 'Hello there, this is matlab.\n');
    fclose(ofid);
end

It runs as expected when called from the Matlab console. However, when I compile the file to an executable using mcc

/opt/matlab/matlab2008a/bin/mcc -m hello.m

and run it as

./hello

It seems to run forever and produces no hello.txt file. Both the executable as well as the Matlab function files are in the Matlab working directory.

I am unable to see what can be possibly wrong in my use of mcc. Please help.


Solution

  • Typically, you need to setup the MATLAB runtime environment when executing mcc compiled applications.

    You'll probably get more mileage the first time by using deploytool (from the command line) to compile your hello.m program here. MATLAB's application builder will produce a run_hello.sh file that you can peruse through to see how they setup their libraries. Then, to execute your program you would actually call it like this:

    ./run_hello.sh /Applications/MATLAB/MATLAB_Runtime/v90/

    Note: I have just included a generic location for the MATLAB runtime environment, but the actual location will vary depending on your platform and version of MATLAB you built the application with.