Can't run executable created by MCC, of m-code containing EML directives.

Hi,
My project is intended to be compiled by mcc into an executable, on linux using version r2009b, though I'm having the following problem with later versions as well.
I'm trying to start using the embedded matlab compiler (emlmex) on some of its m-files for improving running time, and it seems to work well when run from the matlab command line, without further compilation by mcc.
Some of the functions I have are used both as m-files called from m-files, and as m-files compiled into the eml mex file, so they contain eml directives such as eml.target, eml.extrinsic, eml.varsize etc. It all works well from the matlab command line, but after I compile the project with mcc and try to run the executable, it fails with messages such as:
??? Undefined variable "eml" or class "eml.target".
Code for example - comp_test.m
function [ ] = comp_test( )
if isempty(eml.target)
disp('Regular');
else
disp('EML');
end
end
Compile with: mcc -m comp_test.m Then run: comp_test
or run_comp_test.sh <path to matlab installation >
and get the message: ??? Undefined variable "eml" or class "eml.target".
How do I solve this problem?

 Accepted Answer

The EML directives attempt to call into libraries that are not part of MATLAB Compiler Runtime, so you cannot execute this code in deployed mode. See Ineligible Programs for MATLAB Compiler - you will see that MATLAB Coder (the new product that corresponds to the EML directives) is one of them.
You could wrap your calls to EML directives with the isdeployed flag:
function [ ] = comp_test( )
if ~isdeployed && isempty(eml.target)
disp('Regular');
else
disp('EML');
end
end

4 Comments

Thanks for showing me the ineligible programs list. Now I'm concerned whether it would even be possible to use the mex file generated by emlmex in a complication, as can be done with C files compiled by mex. It would be a shame if it's not possible.
Unfortunately your suggestion doesn't work, as the emlmex compiler doesn't support "isdeployed" and asks that it's declared as extrinsic. It seems like a deadlock.
I'm not very confident that MEX-files generated by emlmex will run in a compiled application because it may try to call into libraries that don't exist. Perhaps you could generate a standalone library using emlc and create a MEX-wrapper to call into them. I believe the code generated using emlc is truly standalone and shouldn't need additional libraries.
Thanks, I'll try that if I find no other way.
Hagay: It looks like isdeployed is supported for code-generation at least in the latest version of MATLAB: http://www.mathworks.com/help/releases/R2011a/toolbox/eml/ug/bq1h2z7-11.html
So upgrading could also be a solution.

Sign in to comment.

More Answers (0)

Categories

Find more on MATLAB Compiler 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!