Include header file in generated code
coder.cinclude(headerfile)
coder.cinclude(headerfile,'InAllSourceFiles',allfiles)
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.
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)
.
Do not call coder.cinclude
inside
run-time conditional constructs such as if
statements, switch
statements, while
-loops,
and for
-loops. You can call coder.cinclude
inside
compile-time conditional statements, such as coder.target
.
For example:
... if ~coder.target('MATLAB') coder.cinclude('foo.h'); coder.ceval('foo'); end ...