Convertcodegen
Command to EquivalentMATLABCoderProject
You can use thecodegen
command with the-toproject
option to convert acodegen
command to an equivalentMATLAB®Coder™project file. You can then generate code from the project file by using anothercodegen
command or theMATLAB Coder应用程序。
For example, to convert acodegen
command with input argumentsinput_arguments
to the project filemyProject.prj
, run:
codegeninput_arguments-toprojectmyProject.prj
Input arguments tocodegen
include:
Names of entry-point functions
Input type definitions specified by using the
-args
optionCode 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
选择将一个不完整的codegen
command to a project file. For example, to create a project filemyProjectTemplate.prj
that contains only the code generation parameters stored in the configuration objectcfg
, run:
codegen-configcfg-toprojectmyProjectTemplate.prj
myProjectTemplate.prj
does not contain specifications of entry-point functions or input types. So, you cannot generate code from this project file. You can openmyProjectTemplate.prj
in theMATLAB Coderapp and use it as a template to create full project files that you can use to generate code.
Note
Running thecodegen
command with the-toproject
option does not generate code. It creates only the project file.
Example: Convert a Completecodegen
Command to a Project File
Define a MATLAB function,myadd
, that returns the sum of two values.
functiony = myadd(u,v)%#codegeny = u + v;end
Create acoder.CodeConfig
object for generating a static library. SetTargetLang
to'C++'
.
cfg = coder.config('lib'); cfg.TargetLang ='C++';
At the MATLAB command line, create and run acodegen
command. Specifymyadd
as the entry-point function. Specify the inputs tomyadd
as variable-size matrices of typedouble
whose dimensions are unbounded. Specifycfg
as the code configuration object. Include the-toproject
option to convert thecodegen
command to an equivalentMATLAB Coderproject file with namemyadd_project.prj
.
codegen-configcfgmyadd-args{coder.typeof(1,[Inf,Inf]),coder.typeof(1,[Inf,Inf])}-toprojectmyadd_project.prj
Project file 'myadd_project.prj' was successfully created.Open Project
The code generator creates the project filemyadd_project.prj
in the current working folder. Runningcodegen
与-toproject
option does not generate code. It creates only the project file.
Generate code frommyadd_project.prj
by using anothercodegen
command.
codegenmyadd_project.prj
The code generator produces a C++ static library functionmyadd
in the
folder, wherework
\codegen\lib\myadd
is your current working directory.work
Example: Convert an Incompletecodegen
Command to a Template Project File
Create acoder.CodeConfig
object for generating a static library. SetTargetLang
to'C++'
.
cfg = coder.config('lib'); cfg.TargetLang ='C++';
At the MATLAB command line, create and run acodegen
command. Specifycfg
as the code configuration object. Include the-toproject
option to convert thecodegen
command to an equivalentMATLAB Coderproject file with namemyProjectTemplate.prj
.
codegen-configcfg-toprojectmyProjectTemplate.prj
Project file 'myProjectTemplate.prj' was successfully created.Open Project
You can now openmyProjectTemplate.prj
in theMATLAB Coderapp and use it as a template to create full project files that you can use to generate code.
Limitations
When you use thecodegen
command with the-toproject
option, these limitations apply:
间g the
CodeTemplate
parameter of acoder.EmbeddedCodeConfig
object to a project file is not supported.Suppose that your
codegen
command for generating a MEX function usescoder.Constant
to define a constant input that is afi
(Fixed-Point Designer)objectobj
.Certain
fi
object properties are enabled by other properties. When you construct afi
object, 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. Seefi对象属性(Fixed-Point Designer).You convert this
codegen
command to a project file by using the-toproject
选择。You build the project file and generate a MEX function. When you passobj
as 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
obj
that are not enabled to their default values before passing it to the MEX function. To do this, define a newfi
objectobj_new
:a = mat2str(obj); obj_new = eval(a);
Pass
obj_new
as the constant input to the generated MEX function.