Main Content

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 shared 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 definematrixlib.mlx.

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

C++ compiler set to 'MinGW64 Compiler (C++)'.
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