Requirements for Building a MATLAB Interface to C/C++ Libraries
R2026bA 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 can compile the headers in a C++ development environment and use the functionality in C++ applications.
C++ Source and Header Files
To publish a MATLAB interface to a C or C++ library, identify specific functionality you want to include in the interface and the associated header files. These inputs are typically used as part of a configuration or script that defines the interface.
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. You can copy relevant .cpp code
into a text editor, remove the main function, and save the file with the
.cpp file extension. The name of this file can be provided as the
SourceFiles input when creating a
clibgen.api.InterfaceDefinition object.
Compiled Library Files
These compiled library files are used during interface generation and build steps. MATLAB supports these 64-bit dynamic libraries:
| Platform | Compiled Library | File 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/C++ library, you need an installed C/C++ compiler that MATLAB supports. For an up-to-date list of supported compilers, see Supported and Compatible Compilers.
Build the interface to the library by using the same compiler that was used to build the C/C++ library. If your library is header-only (does not use a compiled library file), then you can choose any supported C/C++ compiler to build the interface library.
For workflows that automate interface generation, these compiler requirements still apply.
Note
Not every C++ compiler supports every C++ feature.