clibgen.generateLibraryDefinition
Create definition file for C++ library
Syntax
Description
The clibgen.generateLibraryDefinition
function creates a
definition file with a .m
file extension
used to generate a MATLAB® interface to a C++ library. Use this function to:
Select C/C++ files that define the interface. For guidance on which syntax to use, see "Files in Your Library" in Tips.
Select configurations used by the generate step.
Optionally specify configurations to use to define arguments.
Optionally specify compiler build configuration arguments.
After creating the definition file, you optionally can modify the contents to include functionality that the function cannot automatically define. For information about using a library definition file, see Define MATLAB Interface for C++ Library.
You need a C++ compiler that MATLAB supports. You must build the interface library using the same compiler that was used to build the C++ library. If your library is completely defined by source files (does not use a compiled library file), then you can choose any supported C++ compiler to build the interface library. For information about your C++ compilers, type:
mex -setup cpp
Call the build
function on the definition file to create the MATLAB interface file.
clibgen.generateLibraryDefinition(
creates a definition file defined by
InterfaceGenerationFiles
,Libraries
=LibraryFiles)InterfaceGenerationFiles
and
LibraryFiles
.
The name of the definition file
is define
(since R2022b).
By default, libName
.mlibName
is the name of the first file
specified in InterfaceGenerationFiles
. For example, if you
specify a header file named mylibrary.hpp
, then the function
creates a definition file named definemylibrary.m
. If you
specify more than one interface generation file, then you must use the
InterfaceName
name-value argument to specify
libName
.
clibgen.generateLibraryDefinition(
for a library defined by multiple header files, source files, and, if required,
compiled library files.InterfaceGenerationFiles
,SupportingSourceFiles
=SourceFiles)
clibgen.generateLibraryDefinition(
for a library completely defined by
InterfaceGenerationFiles
)InterfaceGenerationFiles
. If your library includes a
compiled library file, then you must specify a Libraries
argument.
clibgen.generateLibraryDefinition(___,
creates the file using one or more name-value arguments. Use this option with
any of the input argument combinations in the previous syntaxes.Name=Value
)
Use the Configuration options to specify the output folder for the definition file or the interface namespace.
Use the C++ Library Settings to specify compiler build and link options.
Use the Definition Configurations to define all specific argument types in the library.
Examples
Input Arguments
Limitations
Saving
LibraryDefinition
objectdefinelibName
into a MAT-file is not supported.Avoid non-ASCII characters in folder and filenames, as some locale settings do not support those characters. For information about locale, see Set Locale and Display Language.
Tips
To recreate a library definition file, call
clibgen.generateLibraryDefinition
with name-value argumentOverwriteExistingDefinitionFiles
set totrue
. When you use this option, the function deletes the files, including edits you might have made to the files.For troubleshooting information, see Troubleshooting C++ Library Definition Issues.
Your library might contain combinations of C/C++ header files, source files, and compiled library files. This table shows how to set the arguments to
clibgen.generateLibraryDefinition
depending on what types of files define your library.Files in Your Library
InterfaceGenerationFiles
ArgumentName-Value Argument(s) Single CPP header file and import library file on Windows.
A.hpp
A.lib
import library file in folderC:\Documents\MATLAB\
"A.hpp"
Libraries="C:\Documents\MATLAB\A.lib"
CPP header file and compiled object file on Linux.
A.hpp
A.so
in folder~/MATLAB/
"A.hpp"
Libraries="~/MATLAB/A.so"
CPP header file and dynamic compiled library file on macOS.
A.hpp
A.dylib
in folder$home/Documents/MATLAB
"A.hpp"
Libraries="$home/Documents/MATLAB/A.dylib"
Completely defined by CPP header and source files. No library files.
Header file
A.hpp
Source file
A.cpp
Example: Header and C++ Source Files
"A.hpp"
SupportingSourceFiles="A.cpp"
Multiple CPP header files, a source file, and a compiled library file. Create interface named
A
.Header files
A.hpp
andB.hpp
Source file
A.cpp
Compiled library file
B.lib
inC:\Documents\MATLAB\
["A.hpp","B.hpp"]
InterfaceName="A"
a
Libraries="C:\Documents\MATLAB\B.lib"
SupportingSourceFiles="A.cpp"
CPP header-only library. The library is completely defined in a header file and does not have a compiled library file.
A.hpp
Example: Header-Only HPP File
"A.hpp"
Not applicable
Completely defined in a CPP source file and does not have a compiled library file.
A.cpp
"A.cpp"
Not applicable
Completely defined by C header and source files. No library files.
A.h
A.c
"A.h"
SupportingSourceFiles="A.c"
CLinkage=true
Single C header file and import library file on Windows.
A.h
A.lib
inC:\Documents\MATLAB\
"A.h"
Libraries="C:\Documents\MATLAB\A.lib"
CLinkage=true
The CPP source file depends on C header and source files.
Source file
myCPP.cpp
Header and source files
A.h
andA.c
inC:\Documents\MATLAB\
"myCPP.cpp"
SupportingSourceFiles="C:\Documents\MATLAB\A.c"
The C library depends on a CPP source file.
Header and source files
A.h
andA.c
inC:\Documents\MATLAB\
Source file
myCPP.cpp
["C:\Documents\MATLAB\A.h", "myCPP.cpp"]
InterfaceName="myCPP"
SupportingSourceFiles="C:\Documents\MATLAB\A.c"
CLinkage=true
Library defined by CPP and C header files with corresponding library files in
C:\Documents\MATLAB\
.myCPP.hpp
myCPP.lib
myC.h
myC.lib
["myCPP.hpp","myC.h"]
InterfaceName="myCPP"
Libraries=["C:\Documents\MATLAB\myCPP.lib","C:\Documents\MATLAB\myC.lib"]
CLinkage=true
The C header file depends on a CPP header file.
A.h
B.hpp
inC:\Documents\MATLAB\
"A.h"
IncludePath="C:\Documents\MATLAB\"
a Because you have multiple header files, you must set the
InterfaceName
name-value argument. For example, if you setInterfaceName
to"A"
, then when you call library functionfunctionname
from MATLAB, the syntax isclib.A.functionname
.
Alternative Functionality
Live Task
Call the clibPublishInterfaceWorkflow
function to use the Generate C++
Interface live task.
Version History
Introduced in R2019aSee Also
clibPublishInterfaceWorkflow
| Generate C++
Interface | build
| clibgen.buildInterface
| doc