Main Content

Requirements for Building Interface to C++ Libraries

A compiled library is a collection of classes and functions dynamically loaded by an application at run time. The MATLAB® interface to a C++ compiled 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 .cpp file extension. The name of this file is the SourceFiles argument for the clibgen.buildInterface or clibgen.generateLibraryDefinition functions.

Compiled Library Files

MATLAB supports 64-bit dynamic libraries on these platforms:

PlatformCompiled 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, C++ compiler that MATLAB supports. For an up-to-date list of supported compilers, see Supported and Compatible Compilers.

You must build the interface to the library by using the same compiler that was used to build the C++ library. If your library is header-only (does not use a compiled 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