Call C Shared Libraries
Functions
loadlibrary |
Load C/C++ shared library into MATLAB |
unloadlibrary |
Unload shared library from memory |
libisloaded |
确定共享库是否已加载 |
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 |
Classes
lib.pointer |
Pointer object compatible with C pointer |
Examples and How To
MATLAB includes a sample external library calledshrlibsample
.
ThestringToUpper
function in theshrlibsample
library converts the characters in the input argument to uppercase.
Theshrlibsample
example library contains two functions withc_struct
structure input parameters.
This example shows how to display information about and modify a libstruct object, c_struct.
TheReadenum
function in theshrlibsample
library displays a string that matches the input argument.
ThemultDoubleRef
function in theshrlibsample
library multiplies the input by5
.
Theprint2darray
function in theshrlibsample
library displays the values of a 2-D array with three columns and a variable number of rows.
This example shows how to create a MATLAB® cell array of character vectors, mlStringArray, from the output of the getListOfStrings function.
Concepts
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.
When you pass a MATLAB structure to an external library function:
Many functions in external libraries pass arguments by reference.
MATLAB provides a way to modify header file information by creating a原型文件, a file of MATLAB commands.
Troubleshooting
Limitations to Shared Library Support
The MATLAB shared library interface supports C library routines only.
MATLAB returns pointers to structures.
Errors occur when the shared library is not a valid library.
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.