Build C++ Library Interface and Review Contents - MATLAB & Simulink (original) (raw)
Build From Library Definition File
If you created a library definition file by using the clibgen.generateLibraryDefinition function, then use the build function. For example, for library definition file definelibName
, type:
build(definelibName
)
addpath libName
Display the functionality in the library.
One-Step Build
If your library does not contain pointers or other constructs that require definition, you do not need to create a definition file. Call clibgen.buildInterface directly on the C++ header and library files. For example, to build library libName
defined by header fileheader.hpp
, type:
clibgen.buildInterface('header.hpp
',Verbose=true)
addpath libName
Specify C++ Compiler Standard
Your library might use C++ language constructs which are not supported by the default standard of your selected compiler. For details, see Microsoft C/C++ language conformance by Visual Studio version. To specify the C++ compiler standard for building your interface, use the AdditionalCompilerFlags name-value argument.
clibgen.generateLibraryDefinition("A.hpp",AdditionalCompilerFlags=value)
For example, this table shows the value
to use for the C++17 standard.
AdditionalCompilerFlags=Value
Platform | Compilera | Value for Using C++17 Standard |
---|---|---|
Windows® | Microsoft Visual C++ 2019 | "/std:c++17" "-std=c++17" |
Windows | MinGW64 Compiler (C++) | "-std:c++17" |
Windows | Intel Parallel Studio XE 2020 for C++ with Microsoft Visual Studio 2019 | "/Qstd:c++17" |
Linux® | g++ | "-std=c++17" |
macOS | Xcode | "-std=c++17" |
a For information about supported compilers, see Supported and Compatible Compilers. |
Specify Compiler and Linker Flags
To pass specific compiler and linker flags to the function building an interface, use the AdditionalCompilerFlags or AdditionalLinkerFlags name-value arguments in clibgen.generateLibraryDefinition or clibgen.buildInterface. The function passes these flags to the compiler and linker without any validation. The publisher needs to know how the flags affect the build process.
Review Contents of Interface
MATLAB® automatically copies some C++ comments, if available, from the header and source files into the interface. You can modify or replace this content. For more information, see Publish Help Text for MATLAB Interface to C++ Library.
Use the doc
function to open the documentation in your system web browser, which provides links to display help for library functionality. For example, to verify the included classes for library libname
, type:
Click a link for a class. MATLAB opens a new tab. To display help for class ClassName
, click the Constructor Summary link and verify the content. Click theProperty Summary links. Scan the Method Summary for clib.libname.ClassName
methods.
Build Interface for Debugging
For more information, see Debug C++ Library from MATLAB Interface.
See Also
build | clibgen.LibraryDefinition