By default, MATLAB® Coder™ uses the predefined data types in the generated code. You can use customized data type names by importing custom type definitions from external header files. You can then use your own type definitions in the generated C/C++ code. If you have existing legacy code, you can integrate that code, in the generated C/C++ code. You can import a header file by using either the MATLAB Coder app or the command-line interface.
To import custom types from external header files:
Open the MATLAB Coder app and proceed to the Generate Code page.
Click More Settings.
In the Code Appearance tab, select Enable custom data type replacement.
Specify your custom names for the data types in Enable custom data type replacement table and press Enter.
Select the Import custom types from external header files check box.
In the Header files text field, enter a semicolon-separated
list of external header file names and press Enter. For example,
myHeader1.h;myHeader2.h;myHeader3.h
.
Use the ReplacementTypes.IsExtern
and
ReplacementTypes.HeaderFiles
properties in a coder.EmbeddedCodeConfig
object when you generate code by using
codegen
.
Create a code configuration object for generation of a static library.
cfg = coder.config('lib','ecoder',true);
Specify custom names for the data types. For example, double
is
named as Custom_Double
and int8
is named as
Custom_Int8
in the
code.
cfg.EnableCustomReplacementTypes = true; cfg.ReplacementTypes.double = "Custom_Double"; cfg.ReplacementTypes.int8 = "Custom_Int8";
Specify configuration properties for importing the external header files.
% Include single header file cfg.ReplacementTypes.IsExtern = true; cfg.ReplacementTypes.HeaderFiles = "myHeader.h"; cfg.CustomInclude = 'C:\myFiles'; % Include path of the header file
% Include multiple header files cfg.ReplacementTypes.IsExtern = true; cfg.ReplacementTypes.HeaderFiles = "myHeader1.h;myHeader2.h;myHeader3.h"; cfg.CustomInclude = '"C:\Program Files\MATLAB\myFiles"'; % Include path of the header files
For more information on CustomInclude
, see Configure Build by Using the Configuration Object.
Generate code by using codegen
and the
-config
option.
codegen myAdd.m -args {1,int8(1)} -config cfg -report