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

5 次查看(过去 30 天)
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?)

回答(3 个)

Sean de Wolski
Sean de Wolski 2016-10-11
Are you adding the MEX files to the CTF with the -a option in mcc (or as "Other files" in the app)?
  1 个评论
Tom
Tom 2016-10-18
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.

请先登录,再进行评论。


Tom
Tom 2016-10-18
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 2018-8-30
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

类别

Help CenterFile Exchange 中查找有关 MATLAB Compiler 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by