MATLAB Answers

Can an end user without Matlab license use an executable containing the mex command?

37 views (last 30 days)
Carlos on 24 Sep 2012
I have done a Matlab executable which uses the mex command:
eg. system('mex -v -g -LC:\Example\Release -lModel Test.c Test_wrapper.c')
I intend to use it as a standalone exe in a target computer which doesn't have Matlab.
I've installed the correspondent version of MCR in the target computer.
The .exe works fine on my computer, however, when I try to run it on the target computer from the command line, the following message pops up:
" 'mex' is not recognized as an internal or external command, operable programm or batch file "
Am I missing something here? Is it not possible to run a .exe containing Matlab commands on a target machine without Matlab?
On my computer i have:
  • Matlab 2011b (32bit and 64bit, application is compiled using the 32bit)
  • Visual Studio 2010 Ultimate
  • Windows 7 (x64)
On target computer:
  • Visual Studio 2010 Ultimate
  • Windows XP (x64)
Any help will be highly appreciated! Thanks in advance!

Accepted Answer

Carlos on 27 Sep 2012
Hi, here's the answer from Matlab support, I thought it is worthwhile publishing it if anyone has had the same idea as me. Thanks everybody for your help!
<<MATLAB Compiler does not support the MEX function; now it looks like you somehow try to work around that by calling MEX externally. Which may perhaps work if you have a full MATLAB installation, but the external MEX command definitely is not included in the MATLAB Compiler Runtime (MCR).
If you somehow want to be able to call dynamically generated/compiled C/C++ code from your MATLAB Compiler application you will need to do the following:
1. Implement the dynamic part of the C/C++ code in a separate DLL which you compile by yourself using an external compiler.
2. Implement a MEX-file which uses the operating system's LoadLibrary and GetProcAddress to call this external DLL.
The MEX-file then gets compiled into your MATLAB Compiler standalone and the external DLL can be kept external and recreated and recompiled using your own compiler; of course this compiler can be called from within your MATLAB code using the DOS/SYSTEM function.>>

More Answers (2)

Walter Roberson
Walter Roberson on 24 Sep 2012
If it will work at all (I do not know), then you have the issue that mex is installed as part of MATLAB, and is not part of MCR, so at the very least components of mex would need to be installed on the target machine.
  1 Comment
Carlos on 25 Sep 2012
Hi Walter,
Thanks a lot for your fast answer. I thought that you could generate a stand alone application from any m-file which uses functions that you're licensed to. Is this not the case? And if not... what are the limitations/exceptions?
Would it be possible to install selected components from the Matlab installation together with MCR?
The thing is, if I have to install Matlab for the .exe to run on the target machine, then the whole executable approach would lose its meaning (I could then go on directly with the m-file)
Thanks again!

Sign in to comment.

Paul Metcalf
Paul Metcalf on 25 Sep 2012
A mex is used to accelerate a MATLAB operation. It can also be used in cases of parallel computing on the host. It's not designed to be a transportable application, though I can understand your confusion. To do what you are wanting, you need a license for MATLAB Compiler on the host. The targets then only need to install a license free MATLAB runtime called MCR. Be warned, MATLAB compiler is not one of the cheaper addons... Alternatively, since you are using MS Visual Studio, you could use MATLAB Coder, and export the source to MSVS, compiling there. In terms of licensing this will be cheaper. But you may find yourself hitting many walls with functions that are not yet supported in MATLAB Coder. I would therefore recommend the former in your case...
Carlos on 26 Sep 2012
Hi, thanks for your answers! I do have a MATLAB compiler license (v4.16 R2011b), but nevertheless as Walter points out, the mex function doesn't seem to be supported for standalone applications.
THe idea was to be able to call the exe automatically from a server which generates C++ code which I then need to use within MATLAB. I can process the C++ code manually on my computer, but is not as efective as doing it automatically.
What I've finally done is install an old MATLAB version on the server with reduced capabilities but mex support and then call directly my m-file for mex generation from the server via a DOS batch file.
Still, if any of you has any other ideas, don't hesitate to share! Thank you all.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!