coder.updateBuildInfo - Update RTW.BuildInfo build information object - MATLAB
Update RTW.BuildInfo build information object
Syntax
Description
Use the coder.updateBuildInfo function to customize the
build process of the generated C/C++ source code by adding compiler and linker options,
preprocessor macro definitions, source and include files, and precompiled external
libraries.
coder.updateBuildInfo('addCompileFlags', adds
compiler options to the build information object.options)
coder.updateBuildInfo('addLinkFlags', adds
link options to the build information object.options)
coder.updateBuildInfo('addDefines', adds
preprocessor macro definitions to the build information object.options)
coder.updateBuildInfo(___, assigns
a group name to group)options for later reference.
coder.updateBuildInfo('addLinkObjects', adds
a link object from a file to the build information object.filename,path)
coder.updateBuildInfo('addLinkObjects', specifies
if the link object is precompiled.filename,path,priority,precompiled)
coder.updateBuildInfo('addLinkObjects', specifies
if the object is to be built before being linked or used for linking
alone. If the object is to be built, it specifies if the object is
precompiled.filename,path,priority,precompiled,linkonly)
coder.updateBuildInfo(___, assigns
a group name to the link object for later reference.group)
coder.updateBuildInfo('addNonBuildFiles', adds
a nonbuild-related file to the build information object.filename)
coder.updateBuildInfo('addSourceFiles', adds
a source file to the build information object.filename)
coder.updateBuildInfo('addIncludeFiles', adds
an include file to the build information object.filename)
coder.updateBuildInfo(___, adds
the file from specified path.path)
Examples
collapse all
Add the compiler options -Zi and -Wall during
code generation for function, func.
Anywhere in the MATLAB® code for func,
add the following line:
coder.updateBuildInfo('addCompileFlags','-Zi -Wall');
Generate code for func using the codegen command.
Open the Code Generation Report.
codegen -config:lib -launchreport func
You can see the added compiler options under the Build Logs tab in the Code Generation Report.
Add a source file to the project build information
while generating code for a function, calc_factorial.
Write a header file
fact.hthat declares a C functionfactorial.double factorial(double x);
fact.hwill be included as a header file in generated code. This inclusion ensures that the function is declared before it is called.Save the file in the current folder.
Write a C file
fact.cthat contains the definition offactorial.factorialcalculates the factorial of its input.#include "fact.h" double factorial(double x) { int i; double fact = 1.0; if (x == 0 || x == 1) { return 1.0; } else { for (i = 1; i <= x; i++) { fact *= (double)i; } return fact; } }fact.cis used as a source file during code generation.Save the file in the current folder.
Write a MATLAB function
calc_factorialthat usescoder.cevalto call the external C functionfactorial.Use
coder.updateBuildInfowith option'addSourceFiles'to add the source filefact.cto the build information. Usecoder.cincludeto include the header filefact.hin the generated code.function y = calc_factorial(x) %#codegen coder.cinclude('fact.h'); coder.updateBuildInfo('addSourceFiles', 'fact.c'); y = 0; y = coder.ceval('factorial', x);
Generate code for
calc_factorialusing thecodegencommand.codegen -config:dll -launchreport calc_factorial -args 0
In the Code Generation Report, on the C Code tab, you can see the added source file
fact.c.
Add a link object LinkObj.lib to
the build information while generating code for a function func.
For this example, you must have a link object LinkObj.lib saved
in a local folder, for example, c:\Link_Objects.
Anywhere in the MATLAB code for func,
add the following lines:
libPriority = ''; libPreCompiled = true; libLinkOnly = true; libName = 'LinkObj.lib'; libPath = 'c:\Link_Objects'; coder.updateBuildInfo('addLinkObjects', libName, libPath, ... libPriority, libPreCompiled, libLinkOnly);
Generate a MEX function for func using
the codegen command. Open the Code Generation
Report.
codegen -launchreport func
You can see the added link object under the Build Logs tab in the Code Generation Report.
Add an include path to the build information
while generating code for a function, adder. Include
a header file, adder.h, existing on the path.
When header files do not reside in the current folder, to include them, use this method:
Write a header file
mysum.hthat contains the declaration for a C functionmysum.double mysum(double, double);
Save it in a local folder, for example
c:\coder\myheaders.Write a C file
mysum.cthat contains the definition of the functionmysum.#include "mysum.h" double mysum(double x, double y) { return(x+y); }Save it in the current folder.
Write a MATLAB function
adderthat adds the pathc:\coder\myheadersto the build information.Use
coder.cincludeto include the header filemysum.hin the generated code.function y = adder(x1, x2) %#codegen coder.updateBuildInfo('addIncludePaths','c:\coder\myheaders'); coder.updateBuildInfo('addSourceFiles','mysum.c'); %Include the source file containing C function definition coder.cinclude('mysum.h'); y = 0; if coder.target('MATLAB') % This line ensures that the function works in MATLAB y = x1 + x2; else y = coder.ceval('mysum', x1, x2); end end
Generate code for
adderusing thecodegencommand.codegen -config:lib -launchreport adder -args {0,0}
Open the Code Generation Report. The header file
adder.his included in the generated code.
Input Arguments
collapse all
Build options, specified as a character vector or string scalar. The value must be a compile-time constant.
Depending on the leading argument, options specifies
the relevant build options to be added to the project’s build
information.
| Leading Argument | Values in options |
|---|---|
'addCompileFlags' | Compiler options |
'addLinkFlags' | Link options |
'addDefines' | Preprocessor macro definitions |
The function adds the options to the end of an option vector.
Example: coder.updateBuildInfo('addCompileFlags','-Zi
-Wall')
Name of user-defined group, specified as a character vector or string scalar. The value must be a compile-time constant.
The group option assigns a group name to
the parameters in the second argument.
| Leading Argument | Second Argument | Parameters
Named by group |
|---|---|---|
'addCompileFlags' | options | Compiler options |
'addLinkFlags' | options | Link options |
'addLinkObjects' | filename | Name of file containing linkable objects |
'addNonBuildFiles' | filename | Name of nonbuild-related file |
'addSourceFiles' | filename | Name of source file |
'addSourcePaths' | path | Name of source file path |
You can use group to:
Document the use of specific parameters.
Retrieve or apply multiple parameters together as one group.
File name, specified as a character vector or string scalar. The value must be a compile-time constant.
Depending on the leading argument, filename specifies
the relevant file to be added to the project’s build information.
| Leading Argument | File Specified by filename |
|---|---|
'addLinkObjects' | File containing linkable objects |
'addNonBuildFiles' | Nonbuild-related file |
'addSourceFiles' | Source file |
The function adds the file name to the end of a file name vector.
Example: coder.updateBuildInfo('addSourceFiles',
'fact.c')
Relative path name, specified as a character vector or string scalar. The value must be a compile-time constant.
Depending on the leading argument, path specifies the
relevant path name to be added to the project’s build information. The
function adds the path to the end of a path name vector.
| Leading Argument | Path Specified by
path |
|---|---|
'addLinkObjects' | Path to linkable objects |
'addNonBuildFiles' | Path to nonbuild-related files |
'addSourceFiles',
'addSourcePaths' | Path to source files |
The relative path starts from the current working
folder in which you generate code. In the relative path name,
reference the current working folder by using the
START_DIR macro. For example, suppose that your
source file fact.c is contained in
C:\myCode\mySrcDir, and you generate code from
C:\myCode. Write the path as in this example:
Example: coder.updateBuildInfo('addSourceFiles','fact.c','$(START_DIR)\mySrcDir')
Priority of link objects.
This feature applies only when several link objects are added.
Currently, only a single link object file can be added for every coder.updateBuildInfo statement.
Therefore, this feature is not available for use.
To use the succeeding arguments, include '' as
a placeholder argument.
Variable indicating if the link objects are precompiled, specified as a logical value. The value must be a compile-time constant.
If the link object has been prebuilt for faster compiling and
linking and exists in a specified location, specify true.
Otherwise, the MATLAB
Coder™ build process creates the link object
in the build folder.
If linkonly is set to true,
this argument is ignored.
Data Types: logical
Variable indicating if objects must be used for linking only, specified as a logical value. The value must be a compile-time constant.
If you want that the MATLAB
Coder build process must not
build or generate rules in the makefile for building the specified
link object, specify true. Instead, when linking
the final executable, the process should just include the object.
Otherwise, rules for building the link object are added to the makefile.
You can use this argument to incorporate link objects for which source files are not available.
If linkonly is set to true,
the value of precompiled is ignored.
Data Types: logical
Extended Capabilities
expand all
The coder.updateBuildInfo function support only MATLAB to High-Level Synthesis (HLS) workflow in HDL Coder™.
Version History
Introduced in R2013b