Manage Build Process File Dependencies - MATLAB & Simulink (original) (raw)
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
andsimstruc_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.
The parent system header files (_`model`_.h
) include child subsystem header files (_`subsystem`_.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`_.c
or _`subsystem`_.cpp
includes_`model`_.h
and_`model`__private.h
.
In the figure, files _`model`_.h
,_`model`__private.h
, and_`subsystem`_.h
depend on the header filertwtypes.h
. For ERT system target files, the dependency onrtwtypes.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 ontmwtypes.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.
System Header File | Description and Inclusion Conditions for GRT or ERT System Target Files |
---|---|
<math.h> | Defines math constantsGRT—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: Your model configuration enables parameter . See MAT-file logging.Your model configuration enables parameter External mode. |
<float.h> | Provides floating-point math functionsGRT—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, seeChoose a Code Replacement Library. |
<stddef.h> | Defines NULLGRT and ERT—Generated code includes this file when your model contains a utility function that requires this file. |
<stdio.h> | Provides file I/O functionsGRT—Generated code includes this file when your model includes a To File block.ERT—Generated code includes this file when either: Your model includes a To File block.Your model configuration enables parameter . See MAT-file logging. |
<stdlib.h> | Provides utility functions such as the integer versions ofdiv() and abs()GRT—Generated code includes this file when either: Your model includes a Stateflow® chart.Your model includes a math function block configured formod() or rem(), which generate calls to div().ERT—Generated code includes this file when either: Your model includes a Stateflow chart, and you select model configuration parameterSupport: floating-point numbers.Your model includes a math function block configured formod() or rem(), which generate calls to div(). |
<string.h> | Provides memory functions such as memset() andmemcpy()GRT—Generated code includes this file when your model initialization code calls memset().ERT—Generated code includes this file when a block or model initialization code calls memcpy() ormemset().For a list of relevant blocks, in the Command Window, type:showblockdatatypetableLook for blocks with the N2 note. To omit calls to memset() from model initialization code, select model configuration parameters Remove root level I/O zero initialization and Remove internal data zero initialization. |
Code Generator Header Files
Dependencies in the table for generated header files apply to the system target filesgrt.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 |
---|---|
builtin_typeid_types.h | Defines an enumerated type corresponding to built-in data typesGRT and ERT—Generated code includes this file when one or more of these conditions apply: Your model contains a Stateflow chart that uses messages.Your model configuration enables: . See MAT-file logging.Your model configuration selects C API options at > . |
complex_types.h | Defines complex number typesERT—Generated code includes this file if these conditions apply: Data type replacement is set to Use C data types with fixed-width integers.Support: complex numbers or Support non-inlined S-functions is selected.If Data type replacement is set to Use coder typedefs, then complex number types (if needed) are generated in the rtwtypes.h file. |
dt_info.h | Defines data structures for external modeGRT and ERT—Generated code includes this file when your model configuration enables external mode. |
ext_work.h | Defines external mode functionsGRT and ERT—Generated code includes this file when your model configuration enables external mode. |
fixedpoint.h | Provides fixed-point support for noninlined S-functionsGRT—Generated code includes this file.ERT—Generated code includes this file when your model uses noninlined S-functions. |
model_reference_types.h | Contains type definitions for timing bridgesGRT and ERT—Generated code includes this file when building a reference model or building a model that contains model blocks. |
model_types.h | Defines model-specific data typesGRT and ERT—Generated code includes this file. |
multiword_types.h | Contains type definitions for multiword-wide data types and their word-size chunksGRT and ERT—Generated code includes this file when one or more of these conditions apply: Your model uses multiword data types.Your model configuration selects parameter . See MAT-file logging.Your model configuration selects External mode.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: MultiwordTypeDef to 'User defined'MultiwordLength to the biggest length that is required by your models. |
rtGetInf.hrtGetNaN.hrt_nonfinite.h | Support nonfinite numbersGRT—Generated code includes this file when one or more of these conditions apply: Your model contains S-functions.The generated code requires nonfinite numbers.Your model configuration selects parameter . See MAT-file logging.ERT—Generated code includes this file when one or more of these conditions apply: Your model contains S-functions.The generated code requires nonfinite numbers.Your model configuration selects parameter . See MAT-file logging. |
rt_defines.h | Contains type definitions for special mathematical constants (such as π and e) and defines the UNUSED_PARAMETER macroGRT and ERT—Generated code includes this file when either: The generated code requires a mathematical constant definition.The function body does not access a required model function argument. |
rt_logging.h | Supports MAT-file logging and includes:rtwtypes.h builtin_typeid_types.h multiword_types.h rt_mxclassid.h rtw_matlogging.hGRT—Generated code includes this file.ERT—Generated code includes this file when you model configuration selects parameter . SeeMAT-file logging. |
rt_mxclassid.h | Defines mxArray class ID enumerationsGRT and ERT—Generated code includes this file when the code includesrt_logging.c. |
rtw_continuous.h | Supports continuous timeGRT—Generated code includes this file when the code includes simstruc_types.h. ERT—Generated code includes this file when your model configuration selects parameterSupport: continuous time and when the code does not already include simstruc.h. |
rtw_extmode.h | Supports external modeGRT—Generated code includes this file when the code includes simstruc_types.h.ERT—Generated code includes this file when your model configuration selects external mode and when the code does not already includesimstruc.h. |
rtw_matlogging.h | Supports MAT-file loggingGRT—Generated code includes this file when the code includes simstruc_types.h andrt_logging.h.ERT—Generated code includes this file when the code includes rt_logging.h. |
rtw_solver.h | Supports continuous statesGRT—Generated code includes this file when the code includes simstruc_types.h.ERT—Generated code includes this file when your model configuration selects parameterSupport: continuous time and when the code does not already include simstruc.h. |
rtwtypes.h | Defines code generator data typesGRT—Generated code includes this file. Uses a verbose version of the file, which includestmwtypes.h.ERT—Generated code includes this file if one of these conditions applies: Data type replacement is set to Use coder typedefs.Data type replacement is set to Use C data types with fixed-width integers and Coder typedefs compatibility is selected.See rtwtypes.h.The code generator overwrites the previously generated rtwtypes.h when you enable (previously disabled) support for: Complex numbers (SupportComplex set to'on').Noninlined S-functions (SupportNonInlinedSFcns set to'on')To avoid rewriting rtwtypes.h, you can: Specify support for complex number types for your models even if the models do not currently use complex number types.Disable support for noninlined S-functions. In this case, the use of a noninlined S-function produces an error. To avoid the error, convert the S-function to an inlined S-function. For more information, see Inlining S-Functions.Complex number types (if needed) are generated in the: rtwtypes.h file if Data type replacement is set to Use coder typedefscomplex_types.h file if Data type replacement is set to Use C data types with fixed-width integers |
simstruc.h | Supports calling noninlined S-functions that use theSimstruct definition; also includes:limits.h string.h tmwtypes.h simstruc_types.hGRT—Generated code includes this file.ERT—Generated code includes this file when your model uses noninlined S-functions. |
simstruc_types.h | 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.hGRT—Generated code includes this file when the code includes rtwtypes.h. ERT—Generated code does not include this file. For ERT, rtwtypes.h contains definitions, and model.h contains header files. |
sysran_types.h | Supports external modeGRT—Generated code includes this file when the code includes simstruc_types.h.ERT—Generated code includes this file when your model configuration selects external mode and when the code does not already includesimstruc.h. |
zero_crossing_types.h | 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 ofzero_crossing_types.h is always the same. |