coder.BuildConfig 类
命名空间: coder
代码生成期间的编译上下文
描述
代码生成器会创建一个此类的对象,以便于访问编译上下文。编译上下文封装代码生成器使用的设置,包括:
目标语言
代码生成目标
目标硬件
编译工具链
在为 coder.ExternalDependency
类编写的方法中使用 coder.BuildConfig
方法。
创建对象
代码生成器创建此类的对象。
方法
公共方法
getHardwareImplementation | Get handle of copy of hardware implementation object |
getStdLibInfo | 获取标准库信息 |
getTargetLang | Get target code generation language |
getToolchainInfo | Returns handle of copy of toolchain information object |
isCodeGenTarget | Determine if build context represents specified target |
isMatlabHostTarget | Determine if hardware implementation object target is MATLAB host computer |
示例
使用 coder.BuildConfig
方法访问 coder.ExternalDependency
方法中的编译上下文
此示例说明如何使用 coder.BuildConfig
方法来访问 coder.ExternalDependency
方法中的编译上下文。在此示例中,您使用:
coder.BuildConfig.isMatlabHostTarget
来验证代码生成目标是 MATLAB® 主机。如果主机不是 MATLAB,则报告错误。coder.BuildConfig.getStdLibInfo
来获取链接时和运行时库文件扩展名。使用此信息来更新编译信息。
为包含函数 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 %#codegen methods (Static) function bName = getDescriptiveName(~) bName = 'AdderAPI'; end function tf = isSupportedContext(buildContext) if buildContext.isMatlabHostTarget() tf = true; else error('adder library not available for this target'); end end function updateBuildInfo(buildInfo, buildContext) % Get file extensions for the current platform [~, linkLibExt, execLibExt, ~] = buildContext.getStdLibInfo(); % Add file paths hdrFilePath = fullfile(pwd, 'codegen', 'dll', 'adder'); buildInfo.addIncludePaths(hdrFilePath); % 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 for packaging nbFiles = 'adder'; nbFiles = strcat(nbFiles, execLibExt); buildInfo.addNonBuildFiles(nbFiles,'',''); end %API for library function 'adder' function c = adder(a, b) if coder.target('MATLAB') % running in MATLAB, use built-in addition c = a + b; else % Add the required include statements to the generated function code coder.cinclude('adder.h'); coder.cinclude('adder_initialize.h'); coder.cinclude('adder_terminate.h'); c = 0; % Because MATLAB Coder generated adder, use the % housekeeping functions before and after calling % adder with coder.ceval. coder.ceval('adder_initialize'); c = coder.ceval('adder', a, b); coder.ceval('adder_terminate'); end end end end
扩展功能
C/C++ 代码生成
使用 MATLAB® Coder™ 生成 C 代码和 C++ 代码。
版本历史记录
在 R2013b 中推出
MATLAB 命令
您点击的链接对应于以下 MATLAB 命令:
请在 MATLAB 命令行窗口中直接输入以执行命令。Web 浏览器不支持 MATLAB 命令。
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)