Main Content

Troubleshooting MATLAB Interface to C/C++ Library Run-Time Issues

R2026b

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 that MATLAB does not build into the 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.

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

The library publisher provides information about installing dependent libraries.

For more information, see How do I determine which libraries my MEX file or stand-alone application requires?

MATLAB Terminates Unexpectedly When Calling C++ Library Function

If you build the library in debug mode, it might be incompatible with MATLAB, causing an access violation and the program to terminate or crash. On Windows®, to ensure that a debug build uses the same C/C++ run-time library as MATLAB, see Resolve Incompatible Debug Build for C++ Library on Windows.

MATLAB Interface to C++ Library Compatibility

An interface file that was published with an earlier version of MATLAB usually runs on later versions of MATLAB. If the interface generates errors, republish the interface with the current MATLAB release.

Running an interface published with a newer version of MATLAB on an older version of MATLAB is not supported.

Run-time Errors When Using MATLAB Interface from C++ Engine Application

If your C++ engine application calls MATLAB functions that use a MATLAB interface to a C++ library and you get run-time errors such as bad allocation, verify that you used the same C++ compiler to build the interface and engine application.

To resolve this issue, at the MATLAB command prompt, run these commands:

  1. Select a compiler for the C++ interface library.

    mex -setup C++
  2. Rebuild the interface. For example, rebuild an interface defined by idef, a clibgen.api.InterfaceDefinition object. (since R2026b)

    idef.build

    Before R2026b: Rebuild an interface defined by a header file named "myHeader.hpp".

    clibgen.buildInterface("myHeader.hpp")

  3. Select the same compiler for the C++ engine application.

    mex -setup -client engine C++
  4. Rebuild the engine application. For example, rebuild main.cpp.

    mex -client engine main.cpp

See Also

Topics