MATLAB: How to create a standalon exe of mfile including mexfunction

matlab coderMATLAB Compilermexfunctionstandlone

I created a mfile, including the matlab function and the mexfunction by c++. How do I create a standalon exe of this mfile? The mfile can execute in the Matlab envirement. But I try to create a standlon exe of the mfile and executing without the Matlab envirement.

Best Answer

Since you would like to compile a MEX-function, which needs MATLAB runtime libraries to be executed, the right choice would be for you to pick the MATLAB Compiler product to produce an executable from your MATLAB-file. Note, however, that the MATLAB Compiler Runtime (MCR) needs to be installed on all target machines to be able to run the executable.
If you would like a truly standalone executable, you will need to use MATLAB Coder, which has a stricter set of rules for the MATLAB language subset that you can generate C/C++ code from. However, you cannot generate code from MEX-files, so you might instead want to get rid of the MEX-wrapper and directly call the C code from your MATLAB code using coder.ceval so that the corresponding calls into the C code are directly inlined into the generated code.