Compiler and missing source files
조회 수: 8 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
답변 (2개)
Ashwini Venkatappa
2017년 2월 9일
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
Chris Volpe
2020년 1월 8일
편집: Chris Volpe
2020년 1월 8일
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.
Ashwini Venkatappa
2017년 2월 16일
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.
참고 항목
카테고리
Help Center 및 File Exchange에서 MATLAB Compiler에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!