Documentation

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;
    else
        error('MyLibrary is not available for this target');
    end
end

Parameterize Methods for MATLAB and Generated Code

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

...
if coder.target('MATLAB')
    % running in MATLAB, use built-in addition
    c = a + b;
else
    % running in generated code, call library function
    coder.ceval('adder_initialize');
end
...

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?