This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Call C Functions in Shared Libraries

A shared library is a collection of functions dynamically loaded by an application at run time. This MATLAB® interface supports libraries containing functions defined in C header files.

MATLAB supports dynamic linking on all supported platforms.

PlatformShared LibraryFile Extension

Microsoft® Windows®

dynamic link library file.dll

Linux®

shared object file.so

Apple macOS

dynamic shared library.dylib

A shared library needs a header file, which provides signatures for the functions in the library. A function signature, or prototype, establishes the name of the function and the number and types of its parameters. Specify the full path of the shared library and its header file.

You need an installed MATLAB-supported C compiler. For an up-to-date list of supported compilers, see the Supported and Compatible Compilers website.

MATLAB accesses C routines built into external, shared libraries through a command-line interface. This interface lets you load an external library into MATLAB memory and access functions in the library. Although types differ between the two language environments, usually you can pass types to the C functions without converting. MATLAB converts for you.

Details about using a shared library are in these topics.

If the library function passes arguments, you need to determine the data type passed to and from the function. For information about data, see these topics.

When you are finished working with the shared library, it is important to unload the library to free memory.

See Also

| |

Related Topics