Main Content

compiler.build.cppSharedLibrary

创建C ++共享库

Description

example

compiler.build.cppsharedlibrary(功能文件)creates a C++ shared library using the MATLAB®files specified by功能文件。安装支持万博1manbetxC++ compiler在使用此功能之前。

example

compiler.build.cppsharedlibrary(功能文件,姓名,Value)creates a C++ shared library with options specified using one or more name-value arguments. Options include the interface API, library name, and output directory.

example

compiler.build.cppsharedlibrary(opts)使用使用A指定的选项创建C ++共享库compiler.build.CppSharedLibraryOptionsobjectopts。You cannot specify any other options using name-value arguments.

example

结果= compiler.build.cppSharedLibrary(___)returns build information as acompiler.build.resultsobject using any of the input argument combinations in previous syntaxes. The build information consists of the build type, paths to the compiled files, and build options.

Examples

collapse all

创建一个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.mlocated inMatlabroot\ 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);

构建函数在名称的文件夹中生成以下文件addmatrixcppSharedLibraryin 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与示例应用程序共享库

创建一个C ++库,并使用名称值参数自定义。

For this example, use the fileaddmatrix.mlocated inMatlabroot\ 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_addmatrixcppSharedLibraryin 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.mlocated inMatlabroot\ extern \示例\编译器sdk\c_cpp\matrix

appfile = fullfile(matlabroot,'extern','examples','CompilersDK','C_CPP',“矩阵”,'addmatrix.m');

创建一个cppsharedLibraryOptionsobject 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 existingcppsharedLibraryobject before running the build function again.

opts.FunctionFiles = fullfile(matlabroot,'extern','examples','CompilersDK','C_CPP',“矩阵”,'suptractMatrix.m'); compiler.build.cppSharedLibrary(opts);

通过修改功能文件参数和重新编译,您可以使用相同的选项对象编译多个库。

创建一个C++ library and save information about the build type, compiled files, support packages, and build options to acompiler.build.results目的。

Compile using the filemagicsquare.mlocated inMatlabroot\ 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

collapse all

文件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.mextension.

Example:[“ myfunc1.m”,“ myfunc2.m”]

数据类型:char|细绳|细胞

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''

其他文件和文件夹将包括在C ++共享库中,指定为字符向量,字符串标量,字符串数组或字符向量的单元格数组。路径可以相对于当前的工作目录或绝对值。

Example:'AdditionalFiles',["myvars.mat","data.txt"]

数据类型:char|细绳|细胞

标记以自动包含数据文件,指定为'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',然后您提供的数据文件作为某些功能的输入(例如loadfopen)自动包含在共享库中。

  • If you set this property to'off', then you must add data files to the shared library using the额外的费用property.

Example:'AutoDetectDataFiles','off'

数据类型:logical

标志以启用调试符号,指定为'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

接口API,指定为以下选项之一:

  • 'matlab-data'- 使用MATLABData API.

  • 'mwarray'- 使用MwarrayAPI。

For more information, seeAPI Selection for C++ Shared Library

Example:'Interface','mwarray'

C ++共享库的名称,指定为字符向量或字符串标量。生成库的默认名称是功能文件argument.

Example:“ libraryname”,“ mymagic'

数据类型:char|细绳

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|细绳

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.mextension. For more information and limitations, seeSample Driver File Creation

Example:'samplegenerationfiles',[“ sample1.m”,“ sample2.m”]

数据类型:char|细绳|细胞

万博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|细绳|细胞

旗以控制构建冗长,指定为'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

输出参数

collapse all

建立结果,返回compiler.build.results目的。TheResultsobject contains:

  • 构建类型,是'cppSharedLibrary'

  • 通往以下路径:

    • getstarted.html

    • v2文件夹 (matlab-data仅接口)

    • Library名称.dll(Mwarray仅接口)

    • Library名称。lib(Mwarray仅接口)

    • Library名称。H(Mwarray仅接口)

  • A list of included support packages

  • Build options, specified as acppsharedLibraryOptionsobject

Version History

Introduced in R2021a