Main Content

Generate Interface on macOS

This example creates a library definition file definematrixlib.m for a library with a dynamic shared library file on macOS.

Verify Selected C++ Compiler

You can use any C++ compiler supported by MathWorks. To verify that you have a C++ compiler, type:

mex -setup cpp

This example uses the g++ compiler.

Generate Definition File

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

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

% Name the interface
libname = "matrixlib";

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

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.m contains definitions for 10 constructs supported by MATLAB.
- 5 constructs are fully defined.
- 5 constructs partially defined and commented out.

To include the 5 undefined constructs in the interface, uncomment and complete the definitions in definematrixlib.m.
To build the interface, call build(definematrixlib).

Open Definition File

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

See Also