This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

coder.BuildConfig class

Package: coder

Build context during code generation


The code generator creates an object of this class to facilitate access to the build context. The build context encapsulates the settings used by the code generator including:

  • Target language

  • Code generation target

  • Target hardware

  • Build toolchain

Use coder.BuildConfig methods in the methods that you write for the coder.ExternalDependency class.


The code generator creates objects of this class.


getHardwareImplementationGet handle of copy of hardware implementation object
getStdLibInfoGet standard library information
getTargetLangGet target code generation language
getToolchainInfoReturns handle of copy of toolchain information object
isCodeGenTargetDetermine if build configuration represents specified target
isMatlabHostTargetDetermine if hardware implementation object target is MATLAB host computer

Copy Semantics

Value. To learn how value classes affect copy operations, see Copying Objects (MATLAB) in the MATLAB® documentation.


expand all

This example shows how to use coder.BuildConfig methods to access the build context in coder.ExternalDependency methods. In this example, you use:

  • coder.BuildConfig.isMatlabHostTarget to verify that the code generation target is the MATLAB host. If the host is not MATLAB report an error.

  • coder.BuildConfig.getStdLibInfo to get the link-time and run-time library file extensions. Use this information to update the build information.

Write a class definition file for an external library that contains the function adder.

% This class abstracts the API to an external Adder library.
% It implements static methods for updating the build information
% at compile time and build time.

classdef AdderAPI < coder.ExternalDependency
    methods (Static)
        function bName = getDescriptiveName(~)
            bName = 'AdderAPI';
        function tf = isSupportedContext(ctx)
            if  ctx.isMatlabHostTarget()
                tf = true;
                error('adder library not available for this target');
        function updateBuildInfo(buildInfo, ctx)
            [~, linkLibExt, execLibExt, ~] = ctx.getStdLibInfo();
            % Header files
            hdrFilePath = fullfile(pwd, 'codegen', 'dll', 'adder');
            % Link files
            linkFiles = strcat('adder', linkLibExt);
            linkPath = hdrFilePath;
            linkPriority = '';
            linkPrecompiled = true;
            linkLinkOnly = true;
            group = '';
            buildInfo.addLinkObjects(linkFiles, linkPath, ...
                linkPriority, linkPrecompiled, linkLinkOnly, group);
            % Non-build files
            nbFiles = 'adder';
            nbFiles = strcat(nbFiles, execLibExt);
        %API for library function 'adder'
        function c = adder(a, b)
                % running in MATLAB, use built-in addition
                c = a + b;
                % running in generated code, call library function
                % Because MATLAB Coder generated adder, use the
                % housekeeping functions before and after calling
                % adder with coder.ceval.
                % Call initialize function before calling adder for the
                % first time.
                c = 0;
                c = coder.ceval('adder', a, b);
                % Call the terminate function after
                % calling adder for the last time.

Introduced in R2013b

Was this topic helpful?