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.

Best Practices for Using coder.ExternalDependency

Terminate Code Generation for Unsupported External Dependency

The isSupportedContext method returns true if the external code interface is supported in the build context. If the external code interface is not supported, do not return false. Instead, use error to terminate code generation with an error message. For example:

function tf = isSupportedContext(ctx)
    if  ctx.isMatlabHostTarget()
        tf = true;
        error('MyLibrary is not available for this target');

Parameterize Methods for MATLAB and Generated Code

Parameterize methods that call external functions so that the methods run in MATLAB. For example:

    % running in MATLAB, use built-in addition
    c = a + b;
    % running in generated code, call library function

Parameterize updateBuildInfo for Multiple Platforms

Parameterize the updateBuildInfo method to support multiple platforms. For example, use coder.BuildConfig.getStdLibInfo to get the platform-specific library file extensions.

    [~, linkLibExt, execLibExt, ~] = ctx.getStdLibInfo()
% Link files
linkFiles =  strcat('adder', linkLibExt);
buildInfo.addLinkObjects(linkFiles, linkPath, linkPriority, ...
    linkPrecompiled, linkLinkOnly, group);

See Also

| |

Related Topics

Was this topic helpful?