Main Content

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.

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 file rtwtypes.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:

  1. Set model configuration parameter Shared code placement to 'Shared location' and build the model. The code generator places the utility functions in __sharedutils folder.

  2. 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.

  3. 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 FileDescription and Inclusion Conditions for GRT or ERT System Target Files

<math.h>

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:

  • Your model configuration enables parameter MAT-file logging. See MAT-file logging.

  • Your model configuration enables parameter External mode.

<float.h>

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.

<stddef.h>

Defines NULL

GRT and ERT—Generated code includes this file when your model contains a utility function that requires this file.

<stdio.h>

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:

  • Your model includes a To File block.

  • Your model configuration enables parameter MAT-file logging. See MAT-file logging.

<stdlib.h>

Provides utility functions such as the integer versions of div() and abs()

GRT—Generated code includes this file when either:

  • Your model includes a Stateflow® chart.

  • Your model includes a math function block configured for mod() 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 parameter Support: floating-point numbers.

  • Your model includes a math function block configured for mod() or rem(), which generate calls to div().

<string.h>

Provides memory functions such as memset() and memcpy()

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() or memset().

For a list of relevant blocks, in the Command Window, type:

showblockdatatypetable

Look 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 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 FileDescription and Inclusion Conditions for GRT or ERT System Target Files

builtin_typeid_types.h

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:

  • Your model contains a Stateflow chart that uses messages.

  • Your model configuration enables: MAT-file logging. See MAT-file logging.

  • Your model configuration selects C API options at Code Generation > Interface.

dt_info.h

Defines data structures for external mode

GRT and ERT—Generated code includes this file when your model configuration enables external mode.

ext_work.h

Defines external mode functions

GRT and ERT—Generated code includes this file when your model configuration enables external mode.

fixedpoint.h

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.

model_reference_types.h

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.

model_types.h

Defines model-specific data types

GRT and ERT—Generated code includes this file.

multiword_types.h

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:

  • Your model uses multiword data types.

  • Your model configuration selects parameter MAT-file logging. 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.h

rtGetNaN.h

rt_nonfinite.h

Support nonfinite numbers

GRT—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 MAT-file logging. 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 MAT-file logging. See MAT-file logging.

rt_defines.h

Contains type definitions for special mathematical constants (such as π and e) and defines the UNUSED_PARAMETER macro

GRT 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.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.

rt_mxclassid.h

Defines mxArray class ID enumerations

GRT and ERT—Generated code includes this file when the code includes rt_logging.c.

rtw_continuous.h

Supports continuous time

GRT—Generated code includes this file when the code includes simstruc_types.h.

ERT—Generated code includes this file when your model configuration selects parameter Support: continuous time and when the code does not already include simstruc.h.

rtw_extmode.h

Supports external mode

GRT—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 include simstruc.h.

rtw_matlogging.h

Supports MAT-file logging

GRT—Generated code includes this file when the code includes simstruc_types.h and rt_logging.h.

ERT—Generated code includes this file when the code includes rt_logging.h.

rtw_solver.h

Supports continuous states

GRT—Generated code includes this file when the code includes simstruc_types.h.

ERT—Generated code includes this file when your model configuration selects parameter Support: continuous time and when the code does not already include simstruc.h.

rtwtypes.h

Defines code generator data types

GRT—Generated code includes this file. Uses a verbose version of the file, which includes tmwtypes.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 datatypes for your models even if the models do not currently use complex data 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.

simstruc.h

Supports calling noninlined S-functions that use the Simstruct definition; also includes:

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.

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.h

GRT—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 mode

GRT—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 include simstruc.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 of zero_crossing_types.h is always the same.

Related Topics