Requirements for Building Interface to C++ Libraries

A shared library is a collection of classes and functions dynamically loaded by an application at run time. The MATLAB® interface to a C++ shared library supports libraries containing functionality defined in C++ header and source files. You should be able to compile the headers in a C++ development environment and use the functionality in C++ applications.

Cpp Source and Header Files

To publish a MATLAB interface to a C++ library, identify specific functionality you want to include in the interface and the associated header files containing that functionality.

You can use library example code as a starting point to create an .hpp header file. Example code contains the relevant header files in #include statements. Copy the .cpp code into a text editor. Remove the main function and its implementation. Save the file with the .hpp file extension. The name of this file is the CppFiles argument for the clibgen.buildInterface or clibgen.generateLibraryDefinition functions.

Shared Library Files

MATLAB supports dynamic libraries on these platforms:

PlatformShared LibraryFile Extension

Microsoft® Windows®

Dynamic-link library file

.dll

Import library file

.lib

Linux®

Shared object file

.so

Apple macOS

Dynamic shared library file

.dylib

Compiler Dependencies

To build a MATLAB interface for a C++ library, you need an installed, MATLAB-supported C++ compiler. For an up-to-date list of supported compilers, see Supported and Compatible Compilers.

You must build the interface library using the same compiler that was used to build the C++ library. If your library is header-only (does not use a shared library file), then you can choose any supported C++ compiler to build the interface library.

Note

Not every C++ compiler supports every C++ feature.

Related Topics

External Websites