Contenido principal

Build C/C++ Library Interface and Review Contents

R2026b

When you build a MATLAB® interface to a C/C++ library, you can review the contents of the generated interface.

You build a clibgen.api.InterfaceDefinition object created from a clibgen.api.InterfaceConfiguration object. The InterfaceConfiguration workflow provides programmatic control over which C++ constructs are included in the interface and how they are configured. The InterfaceConfiguration object defines how MATLAB:

  • Locates header files and include paths.

  • Selects which constructs are included in the interface.

  • Applies compiler settings for parsing the C++ library.

For example, this code controls which symbols are included in the interface.

icfg = clibgen.api.InterfaceConfiguration("libname");
icfg.HeaderFiles = "mylibrary.hpp";
icfg.IncludedClasses = pattern("MyClass");
icfg.IncludedFunctions = pattern("myFunction");
idef = clibgen.api.InterfaceDefinition(icfg);

Build from Interface Definition Object

To build interface libName from an InterfaceDefinition object idef, use the build function.

build(idef)
addpath libName

Type idef to display the classes, functions, and enumerations available in the interface.

If expected functionality is missing from the interface, the library might contain unsupported language features or data types, or some constructs might not have been included or fully defined. For more information, see Limitations to C/C++ Support.

Specify C++ Compiler Standard

Your library might use C++ language constructs that are not supported by the default compiler standard. For details, see Microsoft C/C++ language conformance by Visual Studio version. To specify the C++ compiler standard, use the AdditionalCompilerFlags property of the InterfaceDefinition object.

icfg.AdditionalCompilerFlags = value

For example, this table shows the value to use for the C++17 standard.

AdditionalCompilerFlags=Value

Platform

Compiler

a

Value for Using C++17 Standard

Windows®Microsoft Visual C++ 2019

"/std:c++17"
"-std=c++17"

WindowsMinGW64 Compiler (C++)

"-std:c++17"

WindowsIntel Parallel Studio XE 2020 for C++ with Microsoft Visual Studio 2019

"/Qstd:c++17"

Linux®g++

"-std=c++17"

macOSXcode

"-std=c++17"

a For information about supported compilers, see Supported and Compatible Compilers.

Specify Compiler and Linker Flags

To pass compiler and linker flags when building the interface, use the AdditionalCompilerFlags or AdditionalLinkerFlags properties in the InterfaceDefinition object. These values are passed directly to the compiler and linker without any validation. You need to know how the flags affect the build process.

Review Contents of Interface

After generating the interface, verify which constructs are available and how they are represented in MATLAB. You can review interface contents in two ways:

  • Programmatically using the InterfaceDefinition object.

  • Interactively by browsing generated documentation.

Inspect Interface Programmatically

When you create an InterfaceDefinition object, MATLAB parses the header files and stores the discovered symbols. These properties show the constructs included in the interface.

idef.Classes
idef.Functions
idef.Enums

Some constructs might not be fully defined or included. You can inspect these using:

idef.IncompleteClasses
idef.IncompleteFunctions

Use this information to identify constructs that require additional definition or configuration.

Browse Interface Documentation

MATLAB can generate documentation for the interface using comments from C++ header and source files. To review the documentation:

doc clib.libname
  • Click a class link to open its documentation.

  • Review Constructor Summary, Property Summary, and Method Summary.

  • Verify that the available functionality matches expectations.

These steps help confirm that the interface contains the expected constructs and behavior.

Build Interface for Debugging

For information about debugging your interface, see Debug C++ Library from MATLAB Interface.

See Also

| |

Topics