Convert codegen Command to Equivalent MATLAB
Coder Project
You can use the codegen command with the
-toproject option to convert a codegen command
to an equivalent MATLAB®
Coder™ project file. You can then generate code from the project file by using
another codegen command or the MATLAB
Coder app.
For example, to convert a codegen command with input arguments
input_arguments to the project file
myProject.coderprj,
run:
codegen input_arguments -toproject myProject
Input arguments to codegen include:
Names of entry-point functions
Input type definitions specified by using the
-argsoptionCode generation options, including parameters specified in configuration objects
Names of custom source files to include in the generated code
You can also use the -toproject option to convert an incomplete
codegen command to a project file. For example, to create a project
file myProjectTemplate.coderprj that contains only the code generation
parameters stored in the configuration object cfg,
run:
codegen -config cfg -toproject myProjectTemplate
myProjectTemplate.coderprj
does not contain specifications of entry-point functions or input types. So, you cannot
generate code from this project file. You can open
myProjectTemplate.codercoderprj in the MATLAB
Coder app and use it as a template to create full project files that you can use to
generate code.Note
Running the codegen command with the
-toproject option does not generate code. It creates only the
project file.
Example: Convert a Complete codegen Command to a Project File
Define a MATLAB function, myadd, that returns the sum of two
values.
function y = myadd(u,v) %#codegen y = u + v; end
Create a coder.CodeConfig object for generating a static library.
Set the TargetLang property to "C++".
cfg = coder.config("lib"); cfg.TargetLang = "C++";
At the MATLAB command line, create and run a codegen command. Specify
myadd as the entry-point function. Specify the inputs to
myadd as variable-size matrices of type double
whose dimensions are unbounded. Specify cfg as the code configuration
object. Include the -toproject option to convert the
codegen command to an equivalent MATLAB
Coder project file with name myadd_project.coderprj.
codegen -config cfg myadd -args {coder.typeof(1,[Inf,Inf]),coder.typeof(1,[Inf,Inf])} -toproject myadd_project
The code generator creates the project file myadd_project.coderprj
in the current working folder. Running codegen with the
-toproject option does not generate code. It creates only the
project file.
Generate code from myadd_project.coderprj by using another
codegen command.
codegen myadd_project.coderprjThe code generator produces a C++ static library function myadd in
the folder, where
work\codegen\lib\myadd is your current working
directory.work
Example: Convert an Incomplete codegen Command to a Template Project File
Create a coder.CodeConfig object for generating a static library.
Set the TargetLang property to "C++".
cfg = coder.config("lib"); cfg.TargetLang = "C++";
At the MATLAB command line, create and run a codegen command. Specify
cfg as the code configuration object. Include the
-toproject option to convert the codegen
command to an equivalent MATLAB
Coder project file with name
myProjectTemplate.coderprj.
codegen -config cfg -toproject myProjectTemplate
You can now open myProjectTemplate.coderprj in the MATLAB
Coder app and use it as a template to create full project files that you can use
to generate code.
Limitations
When you use the codegen command with the
-toproject option, these limitations apply:
Exporting the
CodeTemplateparameter of acoder.EmbeddedCodeConfigobject to a project file is not supported.Suppose that your
codegencommand for generating a MEX function usescoder.Constantto define a constant input that is afi(Fixed-Point Designer) objectobj.Certain
fiobject properties are enabled by other properties. When you construct afiobject, these properties are set to their default values unless you explicitly modify them. Inobj, you set one or more properties that are not enabled to non-default values. See Set fi Object Properties (Fixed-Point Designer).You convert this
codegencommand to a project file by using the-toprojectoption. You build the project file and generate a MEX function. When you passobjas the constant input argument to the generated MEX function and run the MEX, the MEX might throw an error.To fix this issue, you must set the properties of
objthat are not enabled to their default values before passing it to the MEX function. To do this, define a newfiobjectobj_new:a = mat2str(obj); obj_new = eval(a);
Pass
obj_newas the constant input to the generated MEX function.