Main Content

Call C fromMATLAB

Directly call C library functions from MATLAB®R2021b or earlier, usingcalllibfunction

A shared library is a collection of functions dynamically loaded by an application at run time. The MATLAB interface supports libraries containing functions defined in C header files. To call functions in C++ libraries, use the interface described inCall C++ from MATLAB.

Functions

loadlibrary Load C shared library intoMATLAB
unloadlibrary Unload shared C library from memory
calllib Call function in C shared library
libfunctions Return information on functions in shared C library
libfunctionsview Display shared C library function signatures in window
libisloaded Determine if shared C library is loaded
libpointer Pointer object for use with shared C library
libstruct ConvertMATLABstructure to C-style structure for use with shared C library

Classes

lib.pointer Pointer object compatible with C pointer

Topics

Troubleshooting

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.

No Matching Signature Error

This error occurs when you call a function without the correct input or output arguments, or if there is an error in the function signature in the header file.

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.