Generate Interface on macOS
This example creates a library definition file
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
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.