Can I use Matlab Coder generated Mex functions on another computer

I've been able to use Matlab Coder to generate Mex Functions that work on my computer; but I cannot find any instructions on how to use these Mex functions on other computers that have Matlab (and that don't have Matlab Coder). Is there a straight forward way to move the c-code it generates to another system to create the mex function?

 Accepted Answer

To run a MEX function generated by MATLAB Coder™, you must have licenses for all the toolboxes that the MEX function requires. For example, if you generate a MEX function from a MATLAB algorithm that uses a Computer Vision System Toolbox™ function or System object, to run the MEX function, you must have a Computer Vision System Toolbox license.
The other computer should also match the architecture of the computer on which the MEX function was generated.
Are you having any specific issues when you try to run the MEX function on another machine?

3 Comments

Thanks for answering so quickly Ryan;
So, I'll try to formulate my question a little better, hopefully that will help:
I'm using Coder to generate a Mex function on R2014a. This is fine, no problems. However, I want to USE the Mex function (or C-code generated from coder) on another computer that has 2013a/2013b installed on it. I would like to do this for a simple code; no special toolboxes required.
I understand that if you have a single C-code file, like the example "yprime.c", you can type "mex yprime.c" and Matlab will create the mex function. However, output from Matlab Coder seems to be very specialized, multiple .c files; and usually a folder called "interface" with more .c files included. I tried collecting all of them into 1 folder, and running the "_coder_filename.c", but this doesn't work. This is even the case if I try to re-build the mex function on my own computer with 2014a, just using the Coder output.
that Coder generates a .bat file, and re-running this .bat file will recreate the mex function on the original computer. However, this .bat file will not work on another version (at least one reason being there are plenty of references to 2014a in the .bat file and .c files from Coder). I tried fixing all 2014a references to the appropriate 2013a, but this still had issues.
I guess to summarize, my question is: Is there a way to directly use, or edit and then use, output from Matlab Coder to generate the Mex Function on another computer with a different version of Matlab (but no special toolboxes being used on either system; just basic loop/matrix algebra code).
The generated MEX function relies on DLLs present in MATLAB. Those DLLs are forward (but not backward) compatible.
Therefore, the MATLAB you are running the generated MEX-function inside needs the same version or a newer version than the version you generated the MEX-function on.
You can create a MEX-function for an earlier version of MATLAB but it is a lot more work. First generate code for a static library. Standalone code (any of the non-MEX targets) generally do not rely on MATLAB's DLLs. Of course, they don't interact with the MATLAB environment at all.
Once you have a standalone library, write your own C MEX entry point by hand that calls the static library. Use the MEX command to create a MEX-function.
Another possibility is to generate a DLL and try loadLibrary. Depending on the nature of the arguments being passed in and out this may work fine.
Most licenses permit you to download and install older versions of MATLAB as well. It may be simplest to generate the MEX function using R2013a assuming that R2013a has the features you require.
Instructions on installing an older version:

Sign in to comment.

More Answers (0)

Categories

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!