外部代码集成
当您有在 C/C++ 中开发的外部代码、自定义代码或原有代码时,可以直接将其集成到您的 MATLAB 代码中。例如:
要调用 C/C++ 函数,请使用
coder.ceval函数。代码生成器将您的 C/C++ 代码集成到从 MATLAB 生成的 C/C++ 代码中。当您要将生成的代码与外部库、优化的代码或在 C/C++ 中开发的目标文件结合使用时,请集成代码。要向外部代码传递或从外部代码传递在 MATLAB 代码中无法定义的数据类型,例如指针类型或用于外部文件 I/O 的
FILE类型,请使用coder.opaque函数。要将您的编译配置为包括外部源文件、头文件、目标文件和库并链接到它们,请使用
coder.updateBuildInfo函数。为了给外部 C 库提供面向对象的接口,请将您的函数调用打包到从
coder.ExternalDependency超类派生的一个类中。要保留某些标识符名称,以便在要与生成的代码集成的自定义 C/C++ 代码中使用,请使用
coder.reservedName函数。要与外部结构体类型对接,请使用
coder.cstructname函数。
类
coder.ExternalDependency | Interface to external code |
coder.BuildConfig | 代码生成期间的编译上下文 |
函数
coder.ceval | 从生成的代码中调用 C/C++ 函数 |
coder.ref | 指示要按引用传递的数据 |
coder.rref | 指示要按引用传递的只读数据 |
coder.wref | 指示要按引用传递的只写数据 |
coder.cinclude | 在生成的代码中包括头文件 |
coder.opaque | 在生成的代码中声明变量 |
coder.reservedName | Generate code that does not use specified identifier names |
coder.updateBuildInfo | 更新 RTW.BuildInfo 编译信息对象 |
主题
- Configure Build for External C/C++ Code
Specify source files and build parameters for external C/C++ code.
- Integrate External Code That Uses Pointers, Structures, and Arrays
Integrate external C code that uses pointers, structures, and arrays into MATLAB code.
- Pass by Reference to and from External C Functions
Pass data by reference to and from an external C function.
- Integrate External Code That Uses Custom Data Types
Use C types that are not native to MATLAB in an external function.
- Develop Interface for External C/C++ Code
Access your external code using a class interface.
- 将 MATLAB 类型映射到生成的代码中的类型
了解代码生成器如何将 MATLAB 数据类型映射到生成的 C/C++ 代码中的数据类型。
- Integrate Multiple Generated C++ Code Projects
Integrate the generated C++ code from two projects into a single larger project.
疑难解答
对代码生成器无法确定外部 C/C++ 函数调用的输出类型时的错误进行故障排除。
