Clear Filters
Clear Filters

How do I make compiled mex files take precedence over m files when using Matlab Compiler?

6 views (last 30 days)
Normally when executing Matlab code, compiled mex files take precedence over m files. So if you have an .m and a compiled mex file, the compiled mex file will be called. Therefore, when using mex files a useful pattern which helps end users is to include an .m file for each mex file, where the .m file displays a message to the user altering them that the mex file has not been compiled. This is useful because otherwise it is hard for the end user to understand the cause of the error.
However, it seems that Matlab Compiler (mcc) has the opposite precedence; i.e. when compiling a function using mcc - m, if a mex file is invoked in the function, but a corresponding .m file exists, then the compiled mex file will be ignored and the .m file will be called instead. So with the above pattern, no compiled mex files will be included and all calls to mex files will fail. In other words, the Matlab Compiler has a different precedence behaviour to the Matlab interpreter.
Is there any way to force the Matlab Compiler mcc to include the compiled mex files in preference to .m files, to match the precedence behaviour of the interpreter? (Other than manually deleting all the corresponding .m files?)

Answers (3)

Sean de Wolski
Sean de Wolski on 11 Oct 2016
Are you adding the MEX files to the CTF with the -a option in mcc (or as "Other files" in the app)?
  1 Comment
Tom
Tom on 18 Oct 2016
I'm using mcc with -a to specify the folders containing the .m and compiled mex files. It seems that if an .m file exists anywhere in the compilation search path, it overrides the compiled mex file.

Sign in to comment.


Tom
Tom on 18 Oct 2016
As a workaround I have moved the .m files into a separate folder and made sure that folder is removed from the Matlab path and all of the search paths specified with -a when I call mcc to compile. I also have to exclude all parent folders since -a is recursive. This is not really a fix because the behaviour is inconsistent with Matlab's interpreted behaviour, but it gets the compiled app working and calling the compiled mex files correctly.

Hazem
Hazem on 30 Aug 2018
I use the app (from the Apps tab):
Application Compiler
There, you can manually add the mex-files in the box:
Files required for your application to run
if they are not already there. For me, they were automatically detected with Matlab compiler version 9.01

Categories

Find more on MATLAB Compiler in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!