Manage Build Process Files
To apply generated code source and header files from the build process, it is helpful to understand the files that the build process generates and the conditions that control file generation. This information provides access to generated code resources, such as:
Public interface to the model entry points
Enumerated types corresponding to built-in data types
Data structures that describe the model signals, states, and parameters
The code generator creates
files
during the code generation and build process. You can customize the filenames for generated
header, source, and data files. For more information, see Customize Generated File Names. The code generator creates additional folders and
dependency files to support shared utilities and model references. For more information about
the folders that the build process creates, see Manage Build Process Folders. For an example that shows how to use a project to
manage build process folders, see Generate Code and Simulate Models in a Project.model
.*
Depending on model architectures and code generation options, the build process for a GRT-based system target file can produce files that the build process does not generate for an ERT-based system target file. Also, for ERT-based system target files, the build process packages generated files differently than for GRT-based system target files. See Manage File Packaging of Generated Code Modules.
Note
By default, the build process deletes foreign (not generated) source files in the build folder. It is possible to preserve foreign source files in the build folder by following the guidelines in Preserve External Code Files in Build Folder.
The table describes the principal generated files. Within the generated filenames shown in
the table, the model
represents the name of the model for which you
are generating code. The subsystem
represents the name of a
subsystem within the model. When you select the Create code generation
report parameter, the code generator produces a set of HTML files. There is one
HTML file for each source file plus a
model
_contents.html
index file in the
html
subfolder within your build folder. The source and header files in
the table have dependency relationships. For descriptions of other file dependencies, see
Manage Build Process File Dependencies and Add Build Process Dependencies.
File | Description |
---|---|
| Defines an enumerated type corresponding to built-in data types. A model build generates this file when one or more of these conditions apply:
|
| Contains Windows® batch file commands that set the compiler environment and invoke the
For more information about using this file, see model.bat. |
| Corresponds to the model file. The Target Language Compiler generates this C or C++ source code file. The file contains:
|
| Executable program file. A model build generates this file
unless you explicitly specify that the code generator produce code only. The build
generates the executable in the current folder (not the build folder) under control
of the |
| Defines model data structures and a public interface to the model entry
points and data structures. Provides an interface to the real-time model data
structure ( Subsystem
For more information, see model.h. |
| Generated makefile that controls compiling and linking the generated code
into the final binary file by the If you set the
|
| Represents the compiled model. By default, the build process deletes this ASCII file when the build process is complete. You can choose to retain the file for inspection. |
| Contain data structures that describe the model signals, states, and parameters without using external mode. For more information, see Write External Code to Access Generated C API Code. |
| Contains (if conditionally generated) declarations for the parameters data structure and the constant block I/O data structure, and zero representations for structure data types that the model uses. A model build generates this
file when the model uses these data structures. The
|
| Declares structures that contain data type and data type transition information for generated model data structures for supporting external mode. |
| Contains local The generated source files from the model build
include this file. When you interface external code with generated code from a
model, include
For more information, see Manage Build Process File Dependencies. |
| Contains type definitions for timing bridges. A model build generates this file for a referenced model or a model containing model reference blocks. |
| Contains MATLAB® language commands that external mode uses to initialize the external mode connection. |
| Provides forward declarations for the real-time model data structure and the parameters data structure. The generated header files from the model build include this file. Function declarations of reusable functions can use these structures. |
| Contains type definitions for multiple-word wide data types and their word-size chunks. If your code uses multiword data types, include this header file. A model build generates this file when one or more of these conditions apply:
|
| Declares and initializes global nonfinite values for
A model build generates these files when one or more of these conditions apply:
|
| Contains The build
process does not create these modules at code generation time. The modules include
|
| Provides type definitions, For ERT system target files, the code generator creates
For ERT-based system target files that do not generate a
GRT interface and do not have noninlined S-functions, For more information, see rtwtypes.h and Manage Build Process File Dependencies. |
| Marker files. The build process generates these files to help
the |
| Contains type definitions for special mathematical constants (such as π and
e) and defines the A model build generates this file when the generated code requires a mathematical constant definition or when the function body does not access a required model function argument. |
| Provide functions that the noninlined S-functions use in a model. The noninlined S-functions use functions |
| Contains C source code for each noninlined nonvirtual subsystem when the subsystem is configured to place code in a separate file. |
| Contains exported symbols for noninlined nonvirtual subsystems. |
| Serves as a constant obfuscator and is generated when:
The obfuscated code uses random identifiers to disguise constants.
The file contains |
model
.bat
This file contains Windows batch file commands that set the compiler environment and invoke the
make
utility.
If you are using the toolchain approach for the build process, you also can use this
batch file to extract information from the generated makefile,
. The information includes macro
definitions and values that appear in the makefile, such as model
.mkCFLAGS
(C
compiler flags) and CPP_FLAGS
(C++ compiler flags). With the folder
containing
selected as the current
working folder, in the Command Window, type:model
.bat
>> system('model.bat info')
On UNIX and Macintosh platforms, the code generator does not create the
file. To extract information for
toolchain approach builds from the generated makefile on these systems, in the Command
Window, type:model
.bat
>> system('gmake -f model.mk info')
model
.h
The header file
declares model
data structures and a public interface to the model entry points and data structures. This
header file also provides an interface to the real-time model data structure
(model
.h
) by using access macros. If your
code interfaces to model functions or model data structures, include
model
_M
:model
.h
Exported global signals
extern int32_T INPUT; /* '<Root>/In' */
Global structure definitions
/* Block parameters (auto storage) */ extern Parameters_mymodel mymodel_P;
Real-time model (RTM) macro definitions
#ifndef rtmGetSampleTime # define rtmGetSampleTime(rtm, idx) ((rtm)->Timing.sampleTimes[idx]) #endif
Model entry-point functions (ERT example)
extern void mymodel_initialize(void); extern void mymodel_step(void); extern void mymodel_terminate(void);
To generate model entry-point functions in files other than
and
model
.h
, use a function customization
template in the Embedded Coder Dictionary. For more information, see Configure Default C Code Generation for Categories of Data Elements and Functions.model
.c
The main.c
(or .cpp
) file includes
. If the model build generates the
model
.hmain.c
(or .cpp
) file from a TLC script, the TLC
source can include
.model
.h
#include "%<CompiledModel.Name>.h"
If main.c
is a static source file, you can use the fixed header
filename rtmodel.h
. This file includes the
header file:model
.h
#include "model.h" /* If main.c is generated */
or
#include "rtmodel.h" /* If static main.c is used */
Other external source files can require to include
to interface to model data, for
example exported global parameters or signals. The
model
.h
file itself can have additional
header dependencies due to requirements of generated code. See System Header Files and Code Generator Header Files. model
.h
To reduce dependencies and reduce the number of included header files, see Manage Build Process File Dependencies.
rtwtypes.h
When the configuration parameter Data type replacement is set to
Use coder typedefs
, the generated code includes
rtwtypes.h
. The header file rtwtypes.h
defines data
types, structures, and macros required by the generated code.
Often, the generated code requires that integer operations overflow or underflow at
specific values. For example, when the code expects a 16-bit integer, the code does not
accept an 8-bit or a 32-bit integer type. The C language does not set a standard for the
number of bits in types such as char
and int
.
Note
Before the creation of the C99 language standard, there was
no universally accepted data type for sized integers. The
C99 standard provides the header files stdint.h
and
stdbool.h
. The stdint.h
file contains
sized-integer implementations that were previously unavailable.
To accommodate this feature of the C language, the generated code uses sized integer
types, such as int8_T
and uint32_T
, which are not
standard C types. In rtwtypes.h
, the generated code maps these
sized-integer types to the corresponding C keyword base type using information in the
Hardware Implementation pane of the Configuration Parameters
dialog box.
The code generator produces an optimized version of rtwtypes.h
for
ERT-based system target files when the model does not contain noninlined S-functions. The
optimized rtwtypes.h
file contains definitions that are specific to the
hardware configuration of the model.
The location of rtwtypes.h
depends on whether the build process uses
the shared utilities location. If it uses a shared location, the code
generator places rtwtypes.h
in
slprj/target/_sharedutils
. Otherwise, it places
rtwtypes.h
in the build folder
(
).
See Specify Generated Code Interfaces and Control Placement of rtwtypes.h for Shared Utility Code. model
_target
_rtw
Source files include the rtwtypes.h
header file when the source files
use code generator type names or other code generator definitions. For example, files that
declare variables by using a code generator data
type:
uint32_T myvar
In some cases, an S-function, custom source file is compiled, first, by the
mex
command, and second, by the code generation build. During
mex
compilation, rtwtypes.h
is typically
unavailable. To obtain the definitions normally supplied by rtwtypes.h
,
the custom source file can conditionally (through the MATLAB_MEX_FILE
macro definition) include tmwtypes.h
:
#ifdef MATLAB_MEX_FILE #include "tmwtypes.h" #else #include "rtwtypes.h" #endif
A source file for the code generator main.c
(or
.cpp
) file includes rtwtypes.h
without preprocessor
checks.
#include "rtwtypes.h"
Custom source files that the Target Language Compiler generates can also emit the
include
statements into their generated file.
If the Data type replacement configuration parameter is set to
Use C data types with fixed-width integers
, the code generator
does not create rtwtypes.h
because the generated code does not require
definitions from rtwtypes.h
. If the generated code uses static files
under matlabroot
that require Simulink
Coder data type definitions, the software generates a simplified version of
rtwtypes.h
. If you have custom code that includes
rtwtypes.h
, you can force the generation of the simplified version of
rtwtypes.h
by selecting the Coder typedefs
compatibility check box.