To build (publish) a MATLAB interface to a C++ library, you need:
One or more header or source files that contain declarations of all the functions exported by the library. You should be able to compile these files 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 or source files, then the
library file is optional.
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 Use Prebuilt MATLAB Interface to C++ Library.
|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.
Generate and edit the MATLAB
.mlx definition file to customize and define the interface.
Provide documentation for end-users of a MATLAB interface to a C++ Library.
If library functionality is missing, the library might contain unsupported language features or data types.
This example creates a MATLAB interface to a C++ library defined in a header file
This example creates a MATLAB interface to a C++ library defined in a source files
This example creates a Windows version of the MATLAB interface to C++ library
This example creates a Linux version of the MATLAB interface to C++ library
C/C++ library features not supported in MATLAB.
Example code to work around C++ library limitations.
Information for resolving C++ interface issues.
Work around for errors parsing header file on macOS.
How to remove C++ members containing compile-time assertions.