Main Content

Generate Interface on Linux

This example creates a library definition file definematrixlib.mlx for a library with a shared object file on Linux®.

Verify Selected C++ Compiler

You can use any C++ compiler supported by MathWorks. This example uses the g++ compiler for C++ language compilation. To verify that you have a C++ compiler, type:

mex -setup cpp

Generate Definition File

Identify the names and paths to C++ library artifacts.

productPath = fullfile(matlabroot,"extern","examples","cpp_interface");
libPath = fullfile(productPath,"glnxa64");
hppFile = "matrixOperations.hpp";
hppPath = productPath;
libFile = "libmwmatrixOperations.so";

% Name the interface
libname = "matrixlib";

Generate the definition file. MATLAB® creates the definition file definematrixlib.mlx.

clibgen.generateLibraryDefinition(fullfile(hppPath,hppFile), ...
    "Libraries", fullfile(libPath,libFile), ... 
    "PackageName", libname, ...
    "ReturnCArrays",false, ... % treat output as MATLAB arrays
    "OverwriteExistingDefinitionFiles",true)
Warning: Some C++ language constructs in the files for generating interface file are not supported and not imported.

Using g++ compiler.
Definition file definematrixlib.mlx contains definitions for 10 constructs supported by MATLAB.
- 5 construct(s) are fully defined.
- 5 construct(s) partially defined and commented out.

To include the 5 undefined construct(s) in the interface, uncomment and complete the definitions in definematrixlib.mlx.
To build the interface, call build(definematrixlib).

Open Definition File

Open the generated definition file in Live Editor by clicking the link in the output message. Then continue with the next step.

See Also