coder.cinclude
Include header file in generated code
Description
coder.cinclude( includes a
header file in generated C/C++ source code.headerfile)
MATLAB®
Coder™ generates the include statement in the C/C++ source files that are
generated from the MATLAB code that contains the coder.cinclude
call.
For a Simulink model, when a MATLAB Function block includes a call to coder.cinclude, the code generator places the include statement in the C/C++ source file, where the code for corresponding MATLAB Function block is generated.
Note
In most cases, use coder.ceval (MATLAB Coder) with the
"-headerfile" option instead of
coder.cinclude. Use coder.cinclude
only if you use coder.ceval to call multiple C/C++
functions defined in the same header file. You must call
coder.cinclude before the corresponding
coder.ceval call, and you must call
coder.cinclude and coder.ceval in
the same MATLAB function.
coder.cinclude(
uses the headerfile,'InAllSourceFiles',allfiles)allfiles option to determine whether to include the
header file in all generated C/C++ source
files.
If allfiles is true, for MATLAB code and
Simulink models that include the MATLAB Function block, the code
generator places the include statement in all
C/C++ source files, except some utility files. This behavior is the
coder.cinclude behavior from R2016a and earlier releases.
The presence of the include statement in these additional files
can increase compile time and make the generated code less readable. If
allfiles is false, the behavior is the
same as the behavior of coder.cinclude(headerfile).
Examples
Input Arguments
Limitations
Do not call
coder.cincludeinside runtime conditional constructs such asifstatements,switchstatements,while-loops, andfor-loops. You can callcoder.cincludeinside compile-time conditional statements, such ascoder.target. For example:... if ~coder.target('MATLAB') coder.cinclude('foo.h'); coder.ceval('foo'); end ...
Tips
Before a
coder.cevalcall, callcoder.cincludeto include the header file required by the external function thatcoder.cevalcalls.Extraneous include statements in generated C/C++ code can increase compile time and reduce code readability. To avoid extraneous include statements in code generated by MATLAB Coder, follow these best practices:
Place a
coder.cincludecall as close as possible to thecoder.cevalcall that requires the header file.Do not set
allfilestotrue.
For the MATLAB Function block, the code generator generates the include statement in the model source file (for example,
).model.cIn R2016a and earlier releases, for any
coder.cincludecall, MATLAB Coder included the header file in almost all generated C/C++ source files, except for some utility files. If you have code that depends on this legacy behavior, you can preserve the legacy behavior by using this syntax:coder.cinclude(headerfile,'InAllSourceFiles',true)
Extended Capabilities
Version History
Introduced in R2013a
See Also
coder.ceval | coder.target | coder.reservedName (MATLAB Coder)
Topics
- Model Configuration Parameters: Code Generation Custom Code (Simulink Coder)
