Compiler and missing source files

7 visualizzazioni (ultimi 30 giorni)
Todd Welti
Todd Welti il 6 Feb 2017
Modificato: Chris Volpe il 8 Gen 2020
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

Risposte (2)

Ashwini Venkatappa
Ashwini Venkatappa il 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.
  5 Commenti
Todd Welti
Todd Welti il 18 Feb 2019
It has been a little while, but i don't think the code in question had any of those specialized functions in them.
Chris Volpe
Chris Volpe il 8 Gen 2020
Modificato: Chris Volpe il 8 Gen 2020
Yes, I understand the edge cases, Walter. Thank you for reminding me. I was referring specifically to cases where it knows to look for a particular file, can't find it, and yet quietly ignores it. I though I recall receiving errors in the past, but the answer by Ashwini below suggests that this might not have been possible, so maybe I'm imagining it.
The suggestion that the code should be tried out in Matlab first is, of course, correct, but I don't think the failure cases are due to that. Sometimes an entry point may do path setting. The developer may have built the code before and knows that it works, but then pulled a trivial change from the repository and needs to rebuild (not everyone in our group has the compiler license). The developer needs to remember to run all the path setting code before compiling, even if the person who made the actual change ran it and verified correct behavior in Matlab beforehand.

Accedi per commentare.


Ashwini Venkatappa
Ashwini Venkatappa il 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.

Categorie

Scopri di più su MATLAB Compiler in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by