Manage Build Process File Dependencies
An important control of the size of generated code is managing the number and size of included files (dependencies). To reduce the number of system header files and generated header files that generated code requires, it is helpful to understand the dependencies that the build process generates and the conditions that lead to dependencies.
The dependency relationships among generated source and header files appear in the figure.
Arrows coming from a file point to files it includes. Other dependencies exist, for example,
on Simulink® header files tmwtypes.h
and
simstruc_types.h
, plus C or C++ library files. The figure maps inclusion
relations between only those files that are generated in the build folder. These files can
reference utility and model reference code located in a code generation folder. For more
information about the folders and files that the build process creates, see Manage Build Process Folders and Manage Build Process Files.
The two tables identify the conditions that control creation of dependency files for GRT and ERT targets. To manage build-related dependencies, consider how these conditions apply to your model and code generation process. Then, configure model parameters and code generation options to manage build process file dependencies.
Due to differences in file packaging options for code generated with ERT-based system target files, the file dependencies differ slightly from file packaging for code generated with GRT-based system target files. See Manage File Packaging of Generated Code Modules (Embedded Coder).
The parent system header files (
)
include child subsystem header files
(model
.h
). In more layered models,
subsystems similarly include their children's header files in the model hierarchy. As a
consequence, subsystems are able to view recursively into their descendant subsystems and view
into the root system because every subsystem
.h
or subsystem
.c
includes
subsystem
.cpp
and
model
.h
.model
_private.h
In the figure, files
,
model
.h
, and
model
_private.h
depend on the header file
subsystem
.hrtwtypes.h
. For ERT system target files, the dependency on
rtwtypes.h
exists only if Data type replacement is
set to Use coder typedefs
.
If you use system target files that are not based on the ERT system target file, the
source files that you generate can have additional dependencies on
tmwtypes.h
and simstruc_types.h
.
System Header Files
The system header files make function declarations, type definitions, and macro definitions available to the legacy or external code. Some code generation scenarios require including header files that are specific to the code generator product.
The code generator includes some system header files for broadly defined cases. For
example, generated code includes <stddef.h>
when the model contains
a utility function that requires this header file. This approach helps identify header file
dependencies:
Set model configuration parameter Shared code placement to
'Shared location'
and build the model. The code generator places the utility functions in__sharedutils
folder.Use a find-in-file utility (for example, grep utility) to search the
.c
and.h
files in the__sharedutils
folder for#include
. The search results list the utilities with header file dependencies.Use this information to identify utilities to remove from the model and reduce header file dependencies in the generated code.
For more information, see Generate Shared Utility Code for Fixed-Point Functions (Embedded Coder).
System Header File | Description and Inclusion Conditions for GRT or ERT System Target Files |
---|---|
| Defines math constants GRT—Generated code does not include this file. ERT—Generated code includes this file when the code honors your model configuration for solver Stop time and either:
|
| Provides floating-point math functions GRT—Generated code includes this file when your model contains a floating-point math function. ERT—Generated code includes this file when your model contains a floating-point math function, unless a code replacement library entry overrides the function. For more information, see Choose a Code Replacement Library. |
| Defines NULL GRT and ERT—Generated code includes this file when your model contains a utility function that requires this file. |
| Provides file I/O functions GRT—Generated code includes this file when your model includes a To File block. ERT—Generated code includes this file when either:
|
| Provides utility functions such as the integer versions of
GRT—Generated code includes this file when either:
ERT—Generated code includes this file when either:
|
| Provides memory functions such as GRT—Generated code includes this file when your model
initialization code calls ERT—Generated code includes this file when a block or model
initialization code calls For a list of relevant blocks, in the Command Window, type:
Look
for blocks with the N2 note. To omit calls to |
Code Generator Header Files
Dependencies in the table for generated header files apply to the system target files
grt.tlc
and ert.tlc
. System target files derived
from these base system target files can have additional header dependencies. Code generation
for blocks from blocksets, embedded targets, and custom S-functions can introduce additional
header dependencies.
Header File | Description and Inclusion Conditions for GRT or ERT System Target Files |
---|---|
| Defines an enumerated type corresponding to built-in data types GRT and ERT—Generated code includes this file when one or more of these conditions apply:
|
| Defines data structures for external mode GRT and ERT—Generated code includes this file when your model configuration enables external mode. |
| Defines external mode functions GRT and ERT—Generated code includes this file when your model configuration enables external mode. |
| Provides fixed-point support for noninlined S-functions GRT—Generated code includes this file. ERT—Generated code includes this file when your model uses noninlined S-functions. |
| Contains type definitions for timing bridges GRT and ERT—Generated code includes this file when building a reference model or building a model that contains model blocks. |
| Defines model-specific data types GRT and ERT—Generated code includes this file. |
| Contains type definitions for multiword-wide data types and their word-size chunks GRT and ERT—Generated code includes this file when one or more of these conditions apply:
For a model that uses multiword data types, the code generator overwrites the file if the data types are greater in length than those of the model for which code was last generated. To avoid overwriting this file, set:
|
| Support nonfinite numbers GRT—Generated code includes this file when one or more of these conditions apply:
ERT—Generated code includes this file when one or more of these conditions apply:
|
| Contains type definitions for special mathematical constants (such as π
and e) and defines the GRT and ERT—Generated code includes this file when either:
|
| Supports MAT-file logging and includes: rtwtypes.h builtin_typeid_types.h multiword_types.h rt_mxclassid.h rtw_matlogging.h GRT—Generated code includes this file. ERT—Generated code includes this file when you model configuration selects parameter MAT-file logging. See MAT-file logging. |
| Defines GRT
and ERT—Generated code includes this file when the code includes
|
| Supports continuous time GRT—Generated code includes this file when the code
includes ERT—Generated
code includes this file when your model configuration selects parameter
Support: continuous time and when the code does not already
include |
| Supports external mode GRT—Generated code includes this file when the code
includes ERT—Generated
code includes this file when your model configuration selects external mode and
when the code does not already include
|
| Supports MAT-file logging GRT—Generated code includes this file when the code
includes ERT—Generated code includes
this file when the code includes |
| Supports continuous states GRT—Generated code includes this file when the code
includes ERT—Generated
code includes this file when your model configuration selects parameter
Support: continuous time and when the code does not already
include |
| Defines code generator data types GRT—Generated code
includes this file. Uses a verbose version of the file, which includes
ERT—Generated code includes this file if one of these conditions applies:
See rtwtypes.h. The code generator overwrites the previously generated rtwtypes.h when you enable (previously disabled) support for:
To avoid rewriting
|
| Supports calling noninlined S-functions that use the
limits.h string.h tmwtypes.h simstruc_types.h GRT—Generated code includes this file. ERT—Generated code includes this file when your model uses noninlined S-functions. |
| Provides definitions that the generated code uses and includes the header files: rtw_matlogging.h rtw_extmode.h rtw_continuous.h rtw_solver.h sysran_types.h GRT—Generated code includes this file when the code
includes ERT—Generated code
does not include this file. For ERT, |
| Supports external mode GRT—Generated code includes this file when the code
includes ERT—Generated
code includes this file when your model configuration selects external mode and
when the code does not already include
|
| Contains zero-crossing definitions for models with triggered subsystems where the trigger is rising, falling, or either. File is generated only if required by the model as determined by the data type of the trigger signal. GRT—Generated code does not include this file for GRT code generation targets. ERT—Generated code includes this file when a model has a conditionally executed subsystem where a trigger uses zero crossing detection. If generated, the content of
|