This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.

Call C Shared Libraries

Directly call C library functions from MATLAB®


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


lib.pointer Pointer object compatible with C pointer

Examples and How To

Shared Library shrlibsample

MATLAB includes a sample external library called shrlibsample.

Pass String Arguments

The stringToUpper function in the shrlibsample library converts the characters in the input argument to uppercase.

Pass Structures

The shrlibsample example library contains two functions with c_struct structure input parameters.

Explore libstruct Objects

This example shows how to display information about and modify a libstruct object, c_struct.

Pass Enumerated Types

The readEnum function in the shrlibsample library displays a string that matches the input argument.

Pass Pointers

The multDoubleRef function in the shrlibsample library multiplies the input by 5.

Pass Arrays

The print2darray function in the shrlibsample library displays the values of a 2-D array with three columns and a variable number of rows.

Iterate Through an Array

This example shows how to create a MATLAB® cell array of character vectors, mlStringArray, from the output of the getListOfStrings function.


Call Functions in Shared Libraries

How to call functions in external, shared libraries from MATLAB software.

Pass Arguments to Shared Library Functions

How to construct MATLAB arguments compatible with the argument types found in the library functions.

Structure Arguments

When you pass a MATLAB structure to an external library function:

Pointer Arguments

Many functions in external libraries pass arguments by reference.

MATLAB Prototype Files

MATLAB provides a way to modify header file information by creating a prototype file, a file of MATLAB commands.


Limitations to Shared Library Support

The MATLAB shared library interface supports C library routines only.

Limitations Using Structures

MATLAB returns pointers to structures.

Module Not Found Error

This error occurs when the shared library has dependencies which MATLAB cannot find.

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.

Was this topic helpful?