compiler.build.cppSharedLibrary
创建C ++共享库
Syntax
Description
compiler.build.cppsharedlibrary(
creates a C++ shared library using the MATLAB®files specified by功能文件
)功能文件
。安装支持万博1manbetxC++ compiler在使用此功能之前。
compiler.build.cppsharedlibrary(
使用使用A指定的选项创建C ++共享库opts
)compiler.build.CppSharedLibraryOptions
objectopts
。You cannot specify any other options using name-value arguments.
Examples
Create C++ Library
创建一个C++ shared library using a function file that adds two matrices.
In MATLAB, locate the MATLAB function that you want to deploy as a C++ library. For this example, use the fileaddmatrix.m
located in
。Matlabroot
\ extern \示例\编译器sdk\c_cpp\matrix
appfile = fullfile(matlabroot,'extern','examples','CompilersDK','C_CPP',“矩阵”,'addmatrix.m');
Build a C++ library using thecompiler.build.cppSharedLibrary
命令。
compiler.build.cppsharedlibrary(appFile);
构建函数在名称的文件夹中生成以下文件addmatrixcppSharedLibrary
in your current working directory:
getstarted.html
— HTML file that contains information on integrating your shared library.includedSupportPackages.txt
— Text file that lists all support files included in the library.mccexcludedfiles.log
— Log file that contains a list of any toolbox functions that were not included in the application. For information on non-supported functions, seeMATLABCompiler Limitations。readme.txt
- 读取文件文件,其中包含有关部署先决条件的信息以及用于部署的文件列表。requiredMCRProducts.txt
— Text file that contains product IDs of products required byMATLABRuntimeto run the application.未解决的符号
- 包含有关未解决符号的信息的文本文件。v2\generic_interface\readme.txt
- 读取文件文件,其中包含有关部署先决条件的信息以及用于部署的文件列表。v2\generic_interface\magicsquare.ctf
- 包含可部署档案的组件技术文件。
To implement your shared library, see实施C ++ MATLAB数据API与示例应用程序共享库。
Customize C++ Library
创建一个C ++库,并使用名称值参数自定义。
For this example, use the fileaddmatrix.m
located in
。Matlabroot
\ extern \示例\编译器sdk\c_cpp\matrix
appfile = fullfile(matlabroot,'extern','examples','CompilersDK','C_CPP',“矩阵”,'addmatrix.m');
Save the following code in a sample file namedAddMatrixSample1.m
:
a1 = [1 4 7; 2 5 8; 3 6 9]; a2 = a1; a = addmatrix(a1, a2);
Build a C++ library using thecompiler.build.cppSharedLibrary
命令。Use name-value arguments to specify the library name, add a sample file, and use theMwarray
界面。
compiler.build.cppsharedlibrary(appFile,'LibraryName','mwa_addmatrix',...'SampleGenerationFiles','addmatrixSample1.m',...'Interface','mwarray');
The build function creates the following files within a folder namedmwa_addmatrixcppSharedLibrary
in your current working directory:
samples\addmatrixSample1_mwarray.cpp
— C++ sample driver file.getstarted.html
— File that contains information on integrating your shared library.includedSupportPackages.txt
— Text file that lists all support files included in the library.mwa_addmatrix.cpp
— C++ source code file.mwa_addmatrix.def
— Module-definition file that provides the linker with module information.mwa_addmatrix.dll
— Dynamic-link library file.mwa_addmatrix.exports
- 包含所有非静态函数名称的导出文件。mwa_addmatrix.h
— C++ header file.mwa_addmatrix.lib
- 导入库文件。mccexcludedfiles.log
— Log file that contains a list of any toolbox functions that were not included in the application. For information on non-supported functions, seeMATLABCompiler Limitations。readme.txt
- 读取文件文件,其中包含有关部署先决条件的信息以及用于部署的文件列表。requiredMCRProducts.txt
— Text file that contains product IDs of products required byMATLABRuntimeto run the application.未解决的符号
- 包含有关未解决符号的信息的文本文件。
To implement your shared library, see实施C ++ Mwarray API与驱动程序应用程序共享库。
使用选项对象创建多个库
Create multiple C++ libraries using acompiler.build.CppSharedLibraryOptions
目的。
For this example, use the fileaddmatrix.m
located in
。Matlabroot
\ extern \示例\编译器sdk\c_cpp\matrix
appfile = fullfile(matlabroot,'extern','examples','CompilersDK','C_CPP',“矩阵”,'addmatrix.m');
创建一个cppsharedLibraryOptions
object usingappFile
。Use name-value arguments to specify a common output directory, enable debug symbols, and enable verbose output.
opts = compiler.build.CppSharedLibraryOptions(appFile,...'OutputDir','D:\Documents\MATLAB\work\CppLibraryBatch',...“DebugBuild”,on',...'Verbose','on')
opts =带有属性的cppsharedLibraryOptions:接口:'matlab-data'libraryversion:'1.0.0.0'sampleingGenerationFiles:{} functionfiles:{'c:\ program files \ matlab \R2022a\extern\examples\compilersdk\c_cpp\addmatrix.m'} DebugBuild: on LibraryName: 'addmatrix' AdditionalFiles: {} AutoDetectDataFiles: on 万博1manbetxSupportPackages: {'autodetect'} Verbose: on OutputDir: 'D:\Documents\MATLAB\work\ cpplibrarybatch'
Build the C++ shared library using thecppsharedLibraryOptions
目的。
compiler.build.cppsharedlibrary(opts);
To create a new library using the function file减去Matrix.m
使用相同的选项,请使用DOT表示法修改功能文件
argument of the existingcppsharedLibrary
object before running the build function again.
opts.FunctionFiles = fullfile(matlabroot,'extern','examples','CompilersDK','C_CPP',“矩阵”,'suptractMatrix.m'); compiler.build.cppSharedLibrary(opts);
通过修改功能文件
参数和重新编译,您可以使用相同的选项对象编译多个库。
Get Build Information from C++ Library
创建一个C++ library and save information about the build type, compiled files, support packages, and build options to acompiler.build.results
目的。
Compile using the filemagicsquare.m
located in
。Matlabroot
\ extern \示例\编译器
结果= compiler.build.cppSharedLibrary('magicsquare.m')
结果= Results with properties: BuildType: 'cppSharedLibrary' Files: {2×1 cell} IncludedSupportPackages: {} Options: [1×1 compiler.build.CppSharedLibraryOptions]
The文件
属性包含通往的路径v2
文件夹和getstarted.html
。
Input Arguments
功能文件
—文件implementing MATLAB functions
特征向量|字符串标量|字符向量的单元格数|细绳array
文件implementing MATLAB functions, specified as a character vector, a string scalar, a string array, or a cell array of character vectors. File paths can be relative to the current working directory or absolute. Files must have a.m
extension.
Example:[“ myfunc1.m”,“ myfunc2.m”]
数据类型:char
|细绳
|细胞
opts
—C ++库构建选项
compiler.build.CppSharedLibraryOptions
object
C ++库构建选项, specified as acompiler.build.CppSharedLibraryOptions
目的。
姓名-Value Arguments
将可选的参数对name1 = value1,...,namen = valuen
, where姓名
is the argument name and价值
is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.
在R2021a之前,请使用逗号分隔每个名称和值,并附上姓名
用引号。
Example:'冗长','on''
额外的费用
—附加文件
特征向量|字符串标量|字符向量的单元格数|细绳array
其他文件和文件夹将包括在C ++共享库中,指定为字符向量,字符串标量,字符串数组或字符向量的单元格数组。路径可以相对于当前的工作目录或绝对值。
Example:'AdditionalFiles',["myvars.mat","data.txt"]
数据类型:char
|细绳
|细胞
AutoDetectDataFiles
—Flag to automatically include data files
'on'
(默认)|开/关逻辑值
标记以自动包含数据文件,指定为'on'
或者'off'
, or as numeric or logical1
(真的
) or0
(false
)。一个值'on'
相当于真的
, 和'off'
相当于false
。Thus, you can use the value of this property as a logical value. The value is stored as an on/off logical value of typematlab.lang.OnOffSwitchState
。
If you set this property to
'on'
,然后您提供的数据文件作为某些功能的输入(例如load
和fopen
)自动包含在共享库中。If you set this property to
'off'
, then you must add data files to the shared library using the额外的费用
property.
Example:'AutoDetectDataFiles','off'
数据类型:logical
DebugBuild
—Flag to enable debug symbols
'off'
(默认)|开/关逻辑值
标志以启用调试符号,指定为'on'
或者'off'
, or as numeric or logical1
(真的
) or0
(false
)。一个值'on'
相当于真的
, 和'off'
相当于false
。Thus, you can use the value of this property as a logical value. The value is stored as an on/off logical value of typematlab.lang.OnOffSwitchState
。
If you set this property to
'on'
, then the compiled library contains debug symbols.If you set this property to
'off'
,然后编译的库不包含调试符号。
Example:'DebugBuild','on'
数据类型:logical
Interface
—Interface API
'matlab-data'
(默认)|'mwarray'
接口API,指定为以下选项之一:
'matlab-data'
- 使用MATLABData API.'mwarray'
- 使用Mwarray
API。
For more information, seeAPI Selection for C++ Shared Library。
Example:'Interface','mwarray'
Library名称
—姓名of C++ shared library
特征向量|字符串标量
OutputDir
—输出目录的路径
特征向量|字符串标量
Path to the output directory where the build files are saved, specified as a character vector or a string scalar. The path can be relative to the current working directory or absolute.
The default name of the build folder is the library name appended withcppSharedLibrary
。
Example:'OutputDir','D:\Documents\MATLAB\work\mymagiccppSharedLibrary'
数据类型:char
|细绳
SampleGenerationFiles
—MATLAB示例文件
特征向量|字符串标量|字符向量的单元格数|细绳array
MATLAB示例文件used to generate sample C++ library files for functions included within the library, specified as a character vector, a string scalar, a string array, or a cell array of character vectors. Paths can be relative to the current working directory or absolute. Files must have a.m
extension. For more information and limitations, seeSample Driver File Creation。
Example:'samplegenerationfiles',[“ sample1.m”,“ sample2.m”]
数据类型:char
|细绳
|细胞
万博1manbetxsupportPackages
—万博1manbetx支持软件包
'autodetect'
(默认)|'none'
|字符串标量|字符向量的单元格数|细绳array
万博1manbetx支持软件包to include, specified as one of the following options:
'autodetect'
(default) — The dependency analysis process detects and includes the required support packages automatically.'none'
— No support packages are included. Using this option can cause runtime errors.字符串标量,字符向量或字符向量的单元格数组 - 仅包括指定的支持软件包。万博1manbetx要列出已安装的支持软件包或特定文件使万博1manbetx用的软件包,请参见
Compiler.codetools.deployable万博1manbetxsupportpackages
。
。
Example:“万博1manbetx supportpackages”,{'tensorflow模型的深学习工具箱转换器',“ ploces 365-Googlenet网络的深度学习工具箱模型”}
数据类型:char
|细绳
|细胞
冗长
—Flag to control build verbosity
'off'
(默认)|开/关逻辑值
旗以控制构建冗长,指定为'on'
或者'off'
, or as numeric or logical1
(真的
) or0
(false
)。一个值'on'
相当于真的
, 和'off'
相当于false
。Thus, you can use the value of this property as a logical value. The value is stored as an on/off logical value of typematlab.lang.OnOffSwitchState
。
If you set this property to
'on'
,然后“ MATLAB命令”窗口显示在构建过程中指示编译器输出的进度信息。If you set this property to
'off'
, then the command window does not display progress information.
Example:'冗长','on''
数据类型:logical
输出参数
结果
— Build results
compiler.build.results
object
建立结果,返回compiler.build.results
目的。TheResults
object contains:
构建类型,是
'cppSharedLibrary'
通往以下路径:
getstarted.html
v2
文件夹 (matlab-data
仅接口)
(Library名称
.dllMwarray
仅接口)
(Library名称
。libMwarray
仅接口)
(Library名称
。HMwarray
仅接口)
A list of included support packages
Build options, specified as a
cppsharedLibraryOptions
object
Version History
MATLABCommand
You clicked a link that corresponds to this MATLAB command:
通过在MATLAB命令窗口中输入该命令。Web浏览器不支持MATLAB命令。万博1manbetx
选择一个网站
选择一个网站以获取可用的翻译内容,并查看本地事件和优惠。根据您的位置,我们建议您选择:。
您还可以从以下列表中选择一个网站:
如何获得最佳网站性能
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
美洲
- América Latina(Español)
- Canada(English)
- 美国(English)