To build (publish) a MATLAB interface to a C++ library, you need:
One or more header files that contain declarations of all the functions exported by the library. You should be able to compile the headers in a C++ development environment and use the functionality in C++ applications.
A shared library file —
.dll on Windows®,
macOS. If the library is completely
defined in the header files, then the library file
Additionally, an import library file on
A MATLAB-supported C++ compiler.
The MATLAB interface automatically converts C++ function
signatures into MATLAB function signatures. However, some C++
language constructs do not have unique matches in the
MATLAB language. To bridge this gap, MATLAB uses a definition file
.mlx file extension) which a
publisher creates and modifies to provide missing
information. The publisher must have enough C++ language
skills to interpret a function signature and provide the
An example of information the publisher needs to define relates to the use of pointers to pass data to functions. A pointer is a location in memory that indicates the start of a block of data. To pass this data to MATLAB safely, the publisher must specify the size of the data. Generally, the function documentation indicates the size of the data, perhaps as an additional input argument. Using the MATLAB definition file, the publisher specifies the value, and then MATLAB creates the equivalent MATLAB function signature. To display function signatures, see Display Help for MATLAB Interface to C++ Library.
To make this interface available to other MATLAB users, provide them with the MATLAB interface file. The end user puts the shared library file on the system path or run-time path and the interface file on the MATLAB path.
For information about calling functions in the library, see Call C++ Functions from Published MATLAB Interface.
|Summary of packages and classes to support calling C++ library functionality from MATLAB|
Requirements for calling functions in external, shared C++ libraries from MATLAB.
Outline for publishing an interface to a C++ library.
How to update definitions in the MATLAB
.mlx definition file.
Create library definition file from example
This example creates a MATLAB interface to a C++ library defined in a header file
This example creates a MATLAB interface to a Windows C++ library
This example creates a Linux version of the MATLAB interface to C++ library
When you publish an interface, the
clibgen.generateLibraryDefinition function inserts default text about classes and functions.
C/C++ library features not supported in MATLAB.
Information for resolving C++ interface issues.
Work around for errors parsing header file on macOS.
How to remove C++ members containing compile-time assertions.