Generate Interface on Windows
This example creates a library definition file for a library with an import library file on Windows®.
Verify Selected C++ Compiler
You can use any C++ compiler supported by MathWorks. This example uses the MinGW64 Compiler (C++) 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 the C++ library artifacts.
productPath = fullfile(matlabroot,"extern","examples","cpp_interface"); hppFile = "matrixOperations.hpp"; hppPath = productPath; libFile = "matrixOperations.lib"; libname = "matrixlib";
Identify the compiled library. Uncomment and execute one of these statements based on your selected compiler.
%libPath = fullfile(productPath,"win64","mingw64"); %libPath = fullfile(productPath,"win64","microsoft");
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)
C++ compiler set to 'MinGW64 Compiler (C++)'. 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.