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.
In a Simulink® model, when a coder.cinclude
call appears in a
MATLAB Function block, the code generator puts the include
statement in the model header file.
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 almost all C/C++ source
files.
If allfiles
is true
, MATLAB
Coder generates the include statement in almost
all C/C++ source files, except for 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. Use this
option only if your code depends on the legacy behavior. If
allfiles
is false
, the behavior is the
same as the behavior of coder.cinclude(headerfile)
.
In a MATLAB Function block,
coder.cinclude(headerfile,'InAllSourceFiles', allfiles)
is
the same as coder.cinclude(headerfile)
.
Examples
Input Arguments
Limitations
Do not call
coder.cinclude
inside run-time conditional constructs such asif
statements,switch
statements,while
-loops, andfor
-loops. You can callcoder.cinclude
inside 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.ceval
call, callcoder.cinclude
to include the header file required by the external function thatcoder.ceval
calls.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.cinclude
call as close as possible to thecoder.ceval
call that requires the header file.Do not set
allfiles
totrue
.
For the MATLAB Function block, the code generator generates the include statement in the model header file.
In R2016a and earlier releases, for any
coder.cinclude
call, 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)