Compiler and missing source files
19 views (last 30 days)
Why does Matlab compiler not warn you when you run mcc and there is a missing source .m file? I ran it, (using the -v (verbose) switch). It compiles fine, no errors or warnings. Come to find out later that there was an mfile of mine that was not on the path, so the stand alone does not work. Why does Matlab not at least give an error or warning? Seems really strange...
Running 2014b on Mac os
Ashwini Venkatappa on 9 Feb 2017
The reason why the MATLAB compiler does not throw any error when there are missing dependencies on the MATLAB code is because when MCC is compiling, it does not actually run the MATLAB code, so it does not perform code validation.
The basic reasoning is MCC validation of code is minimal, and it is expected that any compiled MATLAB code has been run and tested in MATLAB first before deployment.
The best practice would be to run and test the MATLAB code first in MATLAB.
Ashwini Venkatappa on 16 Feb 2017
R2014b onwards the compiler no longer translates your MATLAB code to C code which then is compiled;
With the new compiler at runtime you basically still have interpreted MATLAB code. This also introduced a completely different dependency analysis. During compile time it try to determine which dependencies are needed and we will include those into the application.
On a really high level this works something like the following. If It encounter a line like: a = foo(1,2,3) We look for functions named "foo" on your MATLABPATH, if there are any we include those with the application, if there are none it assume that "foo(1,2,3)" was not actually an attempt to call function foo with inputs 1, 2 and 3 but you were actually indexing into a variable foo with index 1, 2 and 3 instead. No error will be thrown that "foo" cannot be found.
Note: the -a option for "mcc" can also be used to include whole directories. So On the other computer,the complete packages which need to be compiled into a MATLAB Compiler component you could consider simply adding everything you sent. The risk here of course is that you may be adding way too much and creating larger than necessary packages, also this still would not guarantee that the code can actually run successfully; again It would be recommend running actual (unit) tests on the code which you want to compile right before you compile it.