Main Content

Load and Unload C Shared Library


To use C libraries with MATLAB® R2022a or later, see Call C++ from MATLAB.

To give MATLAB access to functions in a C shared library, first load the library into memory. After you load the library, you can request information about library functions and call them directly from the MATLAB command line.

To load a shared library into MATLAB, use the loadlibrary function. The most common syntax is:


where shrlib is the shared library file name, and hfile is the name of the header file containing the function prototypes.


The header file provides signatures for the functions in the library and is a required argument for loadlibrary.

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

See Also