外部代码集成
当您有在 C/C++ 中开发的外部代码、自定义代码或原有代码时,可以直接将其集成到您的 MATLAB 代码中。要调用 C/C++ 函数,请使用 coder.ceval
函数。要向外部代码传递或从外部代码传递在 MATLAB 代码中无法定义的数据类型,例如指针类型、用于外部文件 I/O 的 FILE
类型或其他类型,请使用 coder.opaque
。通过使用 coder.updateBuildInfo
,将您的编译配置为包括外部源文件、头文件、目标文件和库并链接到它们。为了给外部 C 库提供面向对象的接口,请将您的函数调用打包到从 coder.ExternalDependency
派生的一个类中。
类
coder.ExternalDependency | Interface to external code |
coder.BuildConfig | 代码生成期间的编译上下文 |
函数
coder.ceval | 调用外部 C/C++ 函数 |
coder.read | Read data files at run time in generated code (自 R2023a 起) |
coder.ref | 指示要传引用的数据 |
coder.rref | 指示要传引用的只读数据 |
coder.wref | 指示要按引用传递的只写数据 |
coder.write | Create data files that the generated code reads at run time (自 R2023a 起) |
coder.cinclude | 在生成的代码中包括头文件 |
coder.opaque | 在生成的代码中声明变量 |
coder.reservedName | Generate code that does not use specified identifier names (自 R2020b 起) |
coder.updateBuildInfo | Update build information object RTW.BuildInfo |
主题
- Data Read and Write Considerations
Learn about file formats that you can use with the generated code for data I/O.
- 从生成的代码中调用自定义 C/C++ 代码
将 C/C++ 代码与用于代码生成的 MATLAB 代码集成。
- Configure Build for External C/C++ Code
Specify source files and build parameters for external C/C++ code.
- Develop Interface for External C/C++ Code
Access your external code using a class interface.
- Mapping MATLAB Types to Types in Generated Code
Understand how the code generator maps MATLAB data types to data types in the generated C/C++ code.
- Integrate Multiple Generated C++ Code Projects
Integrate the generated C++ code from two projects into a single larger project.
疑难解答
Unknown Output Type for coder.ceval
Define the output type for external C/C++ function calls.