Dependency Analysis Using MATLAB Compiler
MATLAB®
Compiler™ uses a dependency analysis function to determine the list of necessary files
to include in the generated package. Sometimes, this process generates a large list of
files, particularly when MATLAB object classes exist in the compilation and the dependency analysis process
cannot resolve overloaded methods at package time. MATLAB
Compiler dependency analysis also processes
include
/exclude
files on each pass.
Tip
To improve package time performance and lessen application size, prune the path with
the mcc
command’s
and -N
-p
flags. You can also specify files to include using the mcc -a
flag, the Custom Requirements section in a compiler app, or the
AdditionalFiles
option in a compiler.build
function.
Function Dependency
The dependency analysis process searches for executable content such as:
MATLAB files
P-files
Note
If the MATLAB file corresponding to the p-file is not available, the dependency analysis cannot determine the p-file’s dependencies.
.fig
filesMEX-files
MATLAB
Compiler is not able to discover functions called through an
feval
, eval
, Handle Graphics® callback, or objects loaded from MAT files. To explicitly include the
function(s), use the %#function
pragma. For
example:
function foo %#function bar feval('bar'); end %function foo
The line %#function bar
notifies MATLAB
Compiler that function bar
will be included in the compilation
and is called through feval
.
For more information on including files in your deployable artifact, see Include and Access Files in Packaged Applications.
Include MEX Files, DLLs, or Shared Libraries
When you compile MATLAB functions containing MEX files, ensure that the dependency analysis process can find them. In particular, note that:
Since the dependency analysis function cannot examine MEX files, DLLs, or shared libraries to determine their dependencies, explicitly include all executable files these files require.
If you have any doubts that a MATLAB function called by a MEX file, DLL, or shared library can be found during dependency analysis, then manually include that function.
Not all functions are compatible with the compiler. Check the file
mccExcludedFiles.log
after your build completes. This file lists all functions called from your application that you cannot deploy.
License and Toolbox Dependencies
For details on determining required toolboxes, see the MATLAB answers post How do I determine the required toolboxes and licenses for my MATLAB code?.
Data File Dependency
In addition to executable content, MATLAB
Compiler can detect and automatically include files that your MATLAB functions access by calling any of these
functions: audioinfo
, audioread
, csvread
, daqread
, dlmread
, fileread
, fopen
, imfinfo
, importdata
, imread
, load
, matfile
, mmfileinfo
, open
, readtable
, type
, VideoReader
, xlsfinfo
, xlsread
, xmlread
,
and xslt
.
The compiler app automatically adds detected data files to the deployable archive.
To ensure that a specific file is included and can be accessed in the compiled application, specify the file without a path. This means the file should be accessible from the current directory or any directory listed in the MATLAB path. For example:
fileread('myfile.ext')
Exclude Files From Package
To ignore data files during dependency analysis, use one or more of the following
options. For examples on how to use these options together, see %#exclude
.
Use the
%#exclude
pragma in your MATLAB code to ignore a file or function during dependency analysis.Use the
-X
flag in yourmcc
command to ignore all data files detected during dependency analysis.Use the
AutoDetectDataFiles
option in acompiler.build
function to control whether data files are automatically included in the package. Setting this tofalse
/'off'
/0
is equivalent to using-X
.
Troubleshoot Missing Dependencies
If one or more dependencies cannot be found, MATLAB
Compiler populates the unresolvedSymbols.txt
file with a list of
the missing items. If this file is not empty, you must locate the required dependencies
and ensure they are available by placing them in the search path. Then, repackage your
project. If any dependencies are not deployable, you can still use the functionality in
your code before it is deployed by using the isdeployed
boolean.
Some functionality requires a specific MathWorks® product. You can use the function matlab.codetools.requiredFilesAndProducts
to display a list of
MATLAB files and MathWorks products that may be required to run the specified MATLAB program files.
For more information on MATLAB Compiler limitations and troubleshooting help, see Limitations.
See Also
compiler.build.standaloneApplication
| Standalone Application Compiler | mcc
| isdeployed