coder.BuildConfig 类
命名空间: coder
代码生成期间的编译上下文
描述
代码生成器会创建一个此类的对象,以便于访问编译上下文。编译上下文封装代码生成器使用的设置,包括:
目标语言
代码生成目标
目标硬件
编译工具链
在为 coder.ExternalDependency 类编写的方法中使用 coder.BuildConfig 方法。
创建对象
代码生成器创建此类的对象。
方法
getHardwareImplementation | 获取硬件实现对象的副本的句柄 |
getStdLibInfo | 获取标准库信息 |
getTargetLang | 获取目标代码生成语言 |
getToolchainInfo | 返回工具链信息对象的副本的句柄 |
isCodeGenTarget | 确定编译上下文是否表示指定的目标 |
isMatlabHostTarget | 确定硬件实现对象目标是否为 MATLAB 主机 |
示例
此示例说明如何使用 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 中推出
另请参阅
coder.target | coder.ExternalDependency | coder.HardwareImplementation (MATLAB Coder)
主题
- Develop Interface for External C/C++ Code (MATLAB Coder)
- Build Process Customization (MATLAB Coder)
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- 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)