C++ Libraries

Directly call C++ library functionality from MATLAB®

If you have a C++ shared library that exports functionality that can be called from another application, then you can use these classes and functions directly in MATLAB, passing data back and forth between MATLAB and C++.

To get started, you first must publish an interface library, using the following.

  • A shared library file — .dll on Windows®, .so on Linux®, or .dylib on macOS

  • One or more header files that contain declarations of all the functions exported by the library

  • An import library file (optional) — .lib

  • A MATLAB-supported C++ compiler

If you already have the interface, then you can call functions in the library using the clib.packagename syntax. The library must be on your system or run-time search path. For more information, see Call Functions in C++ Shared Library.

If you call functions in C libraries using the calllib function, then see C Libraries.

If you write C/C++ functions in MEX files, then see C++ MEX Applications or C MEX File Applications.

Functions

clibgen.generateLibraryDefinitionCreate definition file for C++ library
clibgen.buildInterfaceCreate interface to C++ library without definition file
clibReleaseRelease C++ object from MATLAB
underlyingValueUnderlying numeric value for C++ enumeration object created in MATLAB

Classes

clibgen.LibraryDefinitionMATLAB definition for C++ library
clibgen.ClassDefinitionDefinition for MATLAB class corresponding to C++ class
clibgen.ConstructorDefinitionDefinition for MATLAB function corresponding to C++ class constructor
clibgen.PropertyDefinitionDefinition for MATLAB property corresponding to public property of C++ class
clibgen.MethodDefinitionDefinition for MATLAB function corresponding to C++ class method
clibgen.FunctionDefinitionDefinition for MATLAB function corresponding to C++ package function
clibgen.EnumDefinitionDefinition for MATLAB enumeration corresponding to C++ enumeration

Packages

clibgen PackageSummary of packages and classes to support calling C++ library functionality from MATLAB

Topics

Getting Started

System Requirements

Requirements for calling functions in external, shared C++ libraries from MATLAB.

Import C++ Library Functionality into MATLAB

Requirements for importing C++ library functionality into MATLAB.

MATLAB to C++ Data Type Mapping

Correspondence of MATLAB data types to C++ types.

Publish MATLAB Interface to C++ Library

Steps to Publish a MATLAB C++ Library Interface

Outline for publishing an interface to a C++ library.

Define and Publish Interface to Header-Only C++ Library

This example creates a MATLAB interface to a C++ library defined in a header file.

Define and Publish Interface to C++ Shared Library

This example creates a MATLAB interface to a C++ shared library.

Define MATLAB Interface to C++ Library

How to update definitions in the MATLAB .mlx definition file.

Call C++ Functions from Published MATLAB Interface

Call Functions in C++ Shared Library

To call a function in the library, use the MATLAB clib package.

Display Help for MATLABInterface to C++ Library

Display package information and method signatures for MATLAB C++ interface.

Handling Exceptions

Using C++ exceptions in MATLAB.

Troubleshooting

Limitations to C/C++ Support

C/C++ library features not supported in MATLAB.

Troubleshooting C++ Interface Issues

Information for resolving C++ interface issues.

Errors Parsing Header Files on macOS

Work around for errors parsing header file on macOS.

Build Error Due to Compile-Time Checks

How to remove C++ members containing compile-time assertions.