Main Content

Troubleshooting MATLAB Interface to C++ Library Issues

Library Interface Does Not Exist Or Is Not Loaded

MATLAB® searches for the library interface file on the MATLAB path. The interface file for library libname is libnameInterface.ext, where ext is the platform-specific file extension for a shared library file.

Missing or Incorrectly Installed Run-Time Libraries

A library interface is a dynamically linked module that the MATLAB interpreter loads and executes when you call a function in the library. Dynamic linking means that when you call the function, the program looks for dependent libraries. The library might use specialized run-time libraries which are not built into the MATLAB interface. The code for these libraries is not included in the interface; the libraries must be present on your computer when you call the library. The library publisher should provide information about installing dependent libraries.

To find library dependencies:

  • On Windows® systems, download the Dependency Walker utility from the website https://www.dependencywalker.com.

  • On Linux® systems, use:

    ldd -d libname.so
  • On macOS systems, use:

    otool -L libname.dylib

Library Interface Does Not Contain Any Instances Of Type

To see what classes are available, see the documentation for your library. For library libname, type:

doc clib.libname

In some cases, a publisher might create a library interface that does not include classes or other functionality from the original C++ library. For information about how to include missing functionality in the MATLAB interface, see How to Complete Definitions in Library Definition File.

Invalid clib Array Element Type Name

The MATLAB name for a clib array element type includes clib and the library name. For more information, see clibArray.

For example, for library libname containing class MyClass, the clib array type is:

clib.array.libname.MyClass

and the MATLAB element type is:

clib.libname.MyClass

For fundamental C++ types, use upper camel case for the element type name. For example, if the C++ type is double, then the clib array type is:

clib.array.libname.Double

and the MATLAB element type is:

clib.libname.Double

First Letter Of Type Must Be Capitalized

When creating a clib array, MATLAB converts the names of fundamental C++ types to upper camel case.

For example, if the C++ type is signed int, then the MATLAB clib array type for library libname is:

clib.array.libname.SignedInt

and the element type is:

clib.libname.SignedInt

For strings, if the C++ type is std::string, then:

clib.array.libname.std.String % clib array type
clib.libname.std.String       % element type

Access Violation When Calling Library Function

The library file must be built in release mode, using a C++ compiler that MATLAB supports. If you build the library in debug mode, it might be incompatible with MATLAB, resulting in a termination of the program.