coder.updateBuildInfo - Update RTW.BuildInfo build information object - MATLAB (original) (raw)
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',[options](#btx9jnw-options))
adds compiler options to the build information object.
coder.updateBuildInfo('addLinkFlags',[options](#btx9jnw-options))
adds link options to the build information object.
coder.updateBuildInfo('addDefines',[options](#btx9jnw-options))
adds preprocessor macro definitions to the build information object.
coder.updateBuildInfo(___,[group](#btx9jnw-group))
assigns a group name to options
for later reference.
coder.updateBuildInfo('addLinkObjects',[filename](#btx9jnw-filename),[path](#btx9jnw-path))
adds a link object from a file to the build information object.
coder.updateBuildInfo('addLinkObjects',[filename](#btx9jnw-filename),[path](#btx9jnw-path),[priority](#btx9jnw-priority),[precompiled](#btx9jnw-precompiled))
specifies if the link object is precompiled.
coder.updateBuildInfo('addLinkObjects',[filename](#btx9jnw-filename),[path](#btx9jnw-path),[priority](#btx9jnw-priority),[precompiled](#btx9jnw-precompiled),[linkonly](#btx9jnw-linkonly))
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.
coder.updateBuildInfo(___,[group](#btx9jnw-group))
assigns a group name to the link object for later reference.
coder.updateBuildInfo('addNonBuildFiles',[filename](#btx9jnw-filename))
adds a nonbuild-related file to the build information object.
coder.updateBuildInfo('addSourceFiles',[filename](#btx9jnw-filename))
adds a source file to the build information object.
coder.updateBuildInfo('addIncludeFiles',[filename](#btx9jnw-filename))
adds an include file to the build information object.
coder.updateBuildInfo(___,[path](#btx9jnw-path))
adds the file from specified path.
coder.updateBuildInfo(___,[path](#btx9jnw-path),[group](#btx9jnw-group))
assigns a group name to the file for later reference.
coder.updateBuildInfo('addSourcePaths',[path](#btx9jnw-path))
adds a source file path to the build information object.
coder.updateBuildInfo('addIncludePaths',[path](#btx9jnw-path))
adds an include file path to the build information object.
coder.updateBuildInfo(___,[group](#btx9jnw-group))
assigns a group name to the path for later reference.
Examples
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.h
that declares a C functionfactorial
.
double factorial(double x);fact.h
will 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.c
that contains the definition offactorial
.factorial
calculates 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.c
is used as a source file during code generation.
Save the file in the current folder.
3. Write a MATLAB function calc_factorial
that uses coder.ceval
to call the external C function factorial
.
Use coder.updateBuildInfo
with option 'addSourceFiles'
to add the source file fact.c
to the build information. Use coder.cinclude
to include the header file fact.h
in 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);
4. Generate code for calc_factorial
using the codegen
command.
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.h
that contains the declaration for a C functionmysum
.
double mysum(double, double);
Save it in a local folder, for examplec:\coder\myheaders
. - Write a C file
mysum.c
that contains the definition of the functionmysum
.
#include "mysum.h"
double mysum(double x, double y)
{
return(x+y);
}
Save it in the current folder.
3. Write a MATLAB function adder
that adds the path c:\coder\myheaders
to the build information.
Use coder.cinclude
to include the header file mysum.h
in 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
4. Generate code for adder
using the codegen
command.
codegen -config:lib -launchreport adder -args {0,0}
Open the Code Generation Report. The header file adder.h
is included in the generated code.
Input Arguments
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 bypath |
---|---|
'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 theSTART_DIR
macro. For example, suppose that your source file fact.c
is contained inC:\myCode\mySrcDir
, and you generate code fromC:\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
The coder.updateBuildInfo
function support only MATLAB to High-Level Synthesis (HLS) workflow in HDL Coder™.
Version History
Introduced in R2013b