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 function in shared library


  • [x1,...,xN] = calllib(libname,funcname,arg1,...,argN)



[x1,...,xN] = calllib(libname,funcname,arg1,...,argN) calls function, funcname, in library, libname, passing input arguments, arg1,...,argN, and returns output values obtained from funcname in x1,...,xN.


collapse all

Call addStructByRef Function

Load the library.

if ~libisloaded('shrlibsample')

Display function signature.

libfunctionsview shrlibsample
[double, c_structPtr] addStructByRef(c_structPtr)

The input argument is a pointer to a c_struct data type.

Create a MATLAB® structure, struct:

struct.p1 = 4; struct.p2 = 7.3; struct.p3 = -290; 

Call the function.

[res,st] = calllib('shrlibsample','addStructByRef',struct);

Display the results.

res =


unloadlibrary shrlibsample

Input Arguments

collapse all

libname — Name of shared librarycharacter vector

Name of shared library, specified as a character vector. Do not include the path or file extension in libname.

If you call loadlibrary using the alias option, then you must use the alias name for the libname argument.

Data Types: char

funcname — Name of function in librarycharacter vector

Name of function in library, specified as a character vector.

Data Types: char

arg1,...,argN — Input argumentsany type

Input arguments, 1 through N, required by funcname (if any), specified by any type. The funcname argument list specifies the argument type.

Output Arguments

collapse all

x1,...,xN — Output argumentsany type

Output arguments, 1 through N, from funcname (if any), returned as any type. The funcname argument list specifies the argument type.


  • Use with libraries that are loaded using the loadlibrary function.

More About

collapse all


  • MATLAB validates input argument types before calling funcname. If MATLAB displays error messages about data types, check the MATLAB function signature. For example, if funcname is in library mylib type:


    Scroll through the output to find funcname. For more information, refer to your library documentation.

    When you call funcname, that function might display errors. For information about error messages, refer to your library documentation.

Introduced before R2006a

Was this topic helpful?