Main Content

coder.updateBuildInfo

Update build information object RTW.BuildInfo

Description

example

coder.updateBuildInfo('addCompileFlags',options) adds compiler options to the build information object.

coder.updateBuildInfo('addLinkFlags',options) adds link options to the build information object.

coder.updateBuildInfo('addDefines',options) adds preprocessor macro definitions to the build information object.

coder.updateBuildInfo(___,group) assigns a group name to options for later reference.

example

coder.updateBuildInfo('addLinkObjects',filename,path) adds a link object from a file to the build information object.

coder.updateBuildInfo('addLinkObjects',filename,path,priority,precompiled) specifies if the link object is precompiled.

coder.updateBuildInfo('addLinkObjects',filename,path,priority,precompiled,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) assigns a group name to the link object for later reference.

coder.updateBuildInfo('addNonBuildFiles',filename) adds a nonbuild-related file to the build information object.

example

coder.updateBuildInfo('addSourceFiles',filename) adds a source file to the build information object.

coder.updateBuildInfo('addIncludeFiles',filename) adds an include file to the build information object.

coder.updateBuildInfo(___,path) adds the file from specified path.

coder.updateBuildInfo(___,path,group) assigns a group name to the file for later reference.

coder.updateBuildInfo('addSourcePaths',path) adds a source file path to the build information object.

example

coder.updateBuildInfo('addIncludePaths',path) adds an include file path to the build information object.

coder.updateBuildInfo(___,group) assigns a group name to the path for later reference.

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 

Add a source file to the project build information while generating code for a function, calc_factorial.

  1. Write a header file fact.h that declares a C function factorial.

     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.

  2. Write a C file fact.c that contains the definition of factorial. 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

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 

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:

  1. Write a header file mysum.h that contains the declaration for a C function mysum.

    double mysum(double, double);

    Save it in a local folder, for example c:\coder\myheaders.

  2. Write a C file mysum.c that contains the definition of the function mysum.

    #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}

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 ArgumentValues 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 ArgumentSecond ArgumentParameters Named by group
'addCompileFlags'optionsCompiler options
'addLinkFlags'optionsLink options
'addLinkObjects'filenameName of file containing linkable objects
'addNonBuildFiles'filenameName of nonbuild-related file
'addSourceFiles'filenameName of source file
'addSourcePaths'pathName 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 ArgumentFile 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 ArgumentPath 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')

Note

The START_DIR macro is only supported for generating code with MATLAB Coder™.

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

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

GPU Code Generation
Generate CUDA® code for NVIDIA® GPUs using GPU Coder™.

Version History

Introduced in R2013b