coder.ExternalDependency
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 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 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); ...
coder.BuildConfig
| coder.ExternalDependency
| error