Building portable MEX files

11 views (last 30 days)
Tobias Elmøe
Tobias Elmøe on 12 Jul 2011
Hi. My question is how to build MEX files that are portable using the Matlab Coder?
The problem: I can build a MEX file, using Visual Studio C++ Express from auto generated (by Matlab Coder) C code that can run on my system with no problems, but when I try to run it on a different system, without Matlab Coder, I cannot run it even after installing the Visual Studio redistributeable files. The error code I get is: "Invalid MEX file: specific module cannot be found".
The by far optimal solution: I have actually looked deeper into this and found, using DependencyWalker, that a number of DLL files are required in order for the MEX file to run. If they are not present in the system path, or working directory, the MEX file cannot run and gives the above error code.
Can anyone comment/aide on this?
Sincerely, Tobias Elmøe

Accepted Answer

Friedrich
Friedrich on 12 Jul 2011
Hi,
you are getting this error because you compiled with a Visual Studio compiler and during compiling you will link against certain libraries from that Visual Studio. In order to be able to run that mex file on a different machine you have to install the matching redistributable version on the target machine. Matlab is shipped with the 2005 redistributable package. So please install the 2008 or 2010 redist. package on the target machine.
I think the only way to make a mex file portable is to use a 32bit ML and use the LCC for compiling. But this will limit you to use 32bit ML only.
  2 Comments
Tobias Elmøe
Tobias Elmøe on 12 Jul 2011
Hi - Thanks for the answer, but as I said in my question above, I have already installed the redistributable files on the target machine. Without any effect, sadly.
Tobias Elmøe
Tobias Elmøe on 12 Jul 2011
I seem to have pressed accept on the answer, that was an error, sorry!

Sign in to comment.

More Answers (3)

Tobias Elmøe
Tobias Elmøe on 12 Jul 2011
Hello again. I contacted Mathworks Technical Support, who promised to get back to me on email later today or tomorrow. What I don't understand is that there is a MEX library with Matlab as standard. Why does code built to MEX with the Matlab Coder require a special set of DLL files?
Sincerely,
  4 Comments
Friedrich
Friedrich on 12 Jul 2011
Thanks for posting
Tobias Elmøe
Tobias Elmøe on 29 Jul 2011
Hello again, the following answer was provided to me from the Mathworks tech support:
"I further discussed this issue with our developers and they told me they are currently investigating this issue in further detail. The deployment of MATLAB Coder generated MEX-files is not a documented process and the licensing for this is currently under discussion.
[...]
As this topic is under further discussion I cannot provide any further details at this point in time, however there will be changes to this process in the future. Our developers have your contact details and will be in touch with you as soon as more details are available on this.
From a technical support perspective there is not much else I can do at the moment, other than suggest to try the work around above. If you do experience any further issues, please do not hesitate to let me know, otherwise I will consider this request resolved."
There was a suggested workaround, but it is subject to licensing that may change, so it is not really a valid workaround. Fact is the Mathworks calls their product standalone, while that is not the full truth.
Sincerely,
Tobias Elmøe

Sign in to comment.


Alexander Bottema
Alexander Bottema on 12 Jul 2011
Hi Tobias, Do you know what DLLs are missing? When you say that you try to run it on a different system, does this mean that MATLAB is installed (but not MATLAB Coder)? Or do you mean that MATLAB itself is not installed? Thanks, Alexander
  1 Comment
Tobias Elmøe
Tobias Elmøe on 12 Jul 2011
Hi Alexander. The DLL files include, but not limited to, FITOOLS.DLL, LIBEMLRT.DLL, LIBMWEMLRT_RES.DLL, LIBMWFIXEDPOINTCORE.DLL, LIBMWFIXEDPOINTCORE_RES.DLL, and 5 others.
And yes, what I ment was that Matlab Coder was not installed on the different system, but Matlab itself was (v. 2011a on both build and target machine).
Sincerely,

Sign in to comment.


Friedrich
Friedrich on 12 Jul 2011
Hi,
please contact MW Technical Support for this. It seems that ML Coder is not made for deplyoing your mex functions to other ML users.
I think the Technical Support can tell you more about this.
(Simply copying the missing DLLs will violate the license agreement)
  3 Comments
Friedrich
Friedrich on 12 Jul 2011
It really looks like that it is not made for deploying. The MCR provides these DLLs which your mex file is missing. So writing a wrapper function and compiling it into an exe should work fine. But I think there is no easy way to deploy the mex file only.
Contact the Support and mention these two internal numbers: g730952 and g613886 (this should speed things up)
Tobias Elmøe
Tobias Elmøe on 12 Jul 2011
Hi Friedrich, thanks again for your answer. I was thinking of compiling a static c-library with the Coder and then use the MEX wrapper c-code function that is autogenerated when selecting MEX as an output, and then compile these together. It should be possible to modify the makefile to include the static library, but I don't know how unfortunately, I am not the c-code expert...

Sign in to comment.

Categories

Find more on MATLAB Coder in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!