构建 MATLAB 的 C/C++ 库接口
R2026b您可以使用自己维护的 MATLAB 代码编译(发布)MATLAB 的 C 或 C++ 库接口。指定要包含的头文件和符号,仅调整 MATLAB 无法推断的定义,并在各平台和库更新之间一致地重新构建接口。有关概述,请参阅如何发布 C/C++ 库的 MATLAB 接口。
或者,调用 clibPublishInterfaceWorkflow 以获取创建一个特定于平台的接口的引导步骤。
有关从 MATLAB 调用库中函数的信息,请参阅使用预置的 MATLAB C/C++ 库接口。
在 R2026b 之前的版本中: 用于发布接口的选项是调用 clibPublishInterfaceWorkflow 以使用工作流脚本,或使用 clibgen.generateLibraryDefinition 为库创建定义文件。有关详细信息,请参阅如何发布 MATLAB 的 C/C++ 库接口 (R2026a)。
类
clibgen.api.InterfaceConfiguration | Specify configuration for generating MATLAB interface to C/C++ library (自 R2026b 起) |
clibgen.api.InterfaceDefinition | Inspect, customize, and build MATLAB interface definition for C/C++ library (自 R2026b 起) |
函数
clibPublishInterfaceWorkflow | Create live script to publish platform-specific interface for C/C++ library (自 R2023a 起) |
clibgen.generateLibraryDefinition | 为 C++ 库创建定义文件 |
clibgen.buildInterface | 在没有定义文件的情况下创建 C++ 库的接口 |
实时编辑器任务
| 生成 C++ 接口 | Configure and generate MATLAB interface to C/C++ library (自 R2023a 起) |
命名空间
clibgen.api | Summary of programmatic workflow objects for publishing MATLAB interface to C/C++ library (自 R2026b 起) |
clibgen | 使用“生成 C++ 接口”任务或 clibgen.generateLibraryDefinition 函数发布 MATLAB 的 C++ 库接口的类 |
主题
发布 MATLAB 接口
- 如何发布 C/C++ 库的 MATLAB 接口
发布 C/C++ 库接口的大纲。
- Requirements for Building a MATLAB Interface to C/C++ Libraries
Necessary steps to successfully call functions in external, compiled C/C++ libraries from MATLAB.
定义和自定义
- Define MATLAB Interface for C/C++ Library
Generate and edit the MATLAB
clibgen.api.InterfaceDefinitionobject to customize and define the interface. - Publish Help Text for MATLAB Interface to C/C++ Library
Provide documentation for end-users of a MATLAB interface to a C/C++ Library.
共享您的接口
- Distribute MATLAB Interface to C/C++ Library
How to share your MATLAB interface with MATLAB users.
- C++ to MATLAB Data Type Mapping
Correspondence of MATLAB data types to C/C++ types. - Lifetime Management of C++ Objects in MATLAB
MATLAB rules for managing memory for C++ objects created in a MATLAB interface to a C++ compiled library. - Initialize Pointer Members of C++ Structures for MATLAB Interface to Library
Verify that C++ class constructors initialize pointer members.
疑难解答
Build C/C++ Library Interface and Review Contents
When you build a MATLAB interface to a C/C++ library, you can review the contents of the generated interface.
C/C++ library features not supported in MATLAB.
Troubleshooting C/C++ Library Definition Issues
Information for resolving errors when publishing a MATLAB interface to a C/C++ library.
- Resolve Build Error: Multiple Redefinition Linker Errors
- Resolve Build Error: Unresolved External Symbols
- Build Error Due to Compile-Time Checks
- Errors Parsing Header Files on macOS
Troubleshooting MATLAB Interface to C/C++ Library Run-Time Issues
Resolve unexpected run-time errors when calling functions in a published MATLAB interface to a C/C++ compiled library.
Troubleshooting Calls to C/C++ Library Functions
Resolve unexpected issues when calling functions in a C/C++ compiled library.
Debug C++ Library from MATLAB Interface
How to build a debug version of a MATLAB interface to a C++ library.