Main Content

MATLAB 中调用 C

使用 calllib 函数从 MATLAB® R2021b 或更早版本直接调用 C 库函数

共享库是应用程序在运行时动态加载的函数集合。MATLAB 接口支持包含 C 头文件中定义的函数的库。要调用 C++ 库中的函数,请使用 从 MATLAB 中调用 C++中所述的接口。

函数

loadlibrary将 C 共享库加载到 MATLAB
unloadlibrary从内存中卸载共享 C 库
calllib调用 C 共享库中的函数
libfunctions返回 C 共享库中函数的信息
libfunctionsview在窗口中显示 C 共享库函数签名
libisloaded确定是否已加载 C 共享库
libpointer用于 C 共享库的指针对象
libstructMATLAB 结构体转换为 C 样式的结构体以用于 C 共享库

lib.pointer与 C 指针兼容的指针对象

主题

疑难解答

Limitations to Shared Library Support

C language features not supported.

Limitations Using Structures

Rules for using C language structures in a shared library.

Loading Library Errors

Errors occur when the shared library is not a valid library.

(错误)没有匹配的签名

如果您调用的函数没有正确的输入或输出参数,或者头文件中的函数签名中存在错误,则会发生此错误。

MATLAB Terminates Unexpectedly When Calling Function in Shared Library

Some shared libraries, compiled as Microsoft® Windows® 32-bit libraries, use a calling convention that is incompatible with the default MATLAB calling convention.