Main Content

本页翻译不是最新的。点击此处可查看最新英文版本。

外部代码集成

从 MATLAB® 代码调用外部代码

当您有在 C/C++ 中开发的外部代码、自定义代码或原有代码时,可以直接将其集成到您的 MATLAB 代码中。要调用 C/C++ 函数,请使用 coder.ceval 函数。要向外部代码传递或从外部代码传递在 MATLAB 代码中无法定义的数据类型,例如指针类型、用于外部文件 I/O 的 FILE 类型或其他类型,请使用 coder.opaque。通过使用 coder.updateBuildInfo,将您的编译配置为包括外部源文件、头文件、目标文件和库并链接到它们。为了给外部 C 库提供面向对象的接口,请将您的函数调用打包到从 coder.ExternalDependency 派生的一个类中。

coder.ExternalDependencyInterface to external code
coder.BuildConfig代码生成期间的编译上下文

函数

coder.ceval调用外部 C/C++ 函数
coder.readRead data files at run time in generated code (自 R2023a 起)
coder.ref指示要传引用的数据
coder.rref指示要传引用的只读数据
coder.wref指示要按引用传递的只写数据
coder.writeCreate data files that the generated code reads at run time (自 R2023a 起)
coder.cinclude在生成的代码中包括头文件
coder.opaque在生成的代码中声明变量
coder.reservedNameGenerate code that does not use specified identifier names (自 R2020b 起)
coder.updateBuildInfoUpdate build information object RTW.BuildInfo

主题

疑难解答

Unknown Output Type for coder.ceval

Define the output type for external C/C++ function calls.