Integrate C++ Shared Libraries with MATLAB Data API
Workflow to Create C++ Shared Library using Generic Interface
To create a C++ shared library that uses the MATLAB® Data API:
Package your MATLAB code into an archive (
.ctf) file using the Library Compiler app or the
compiler.build.cppSharedLibraryfunction. Select the MATLAB Data interface.
Write C++ code using the generic interface.
Link the driver code against header files provided with MATLAB Runtime.
Run your application.
For an example of this workflow, see Generate a C++ MATLAB Data API Shared Library and Build a C++ Application.
Write C++ Code using Generic Interface
The basic workflow for using the generic interface for C++ shared libraries is as follows:
Call the free function
initMATLABApplication, which optionally takes a vector of run time options such as
-logfile. The function returns a
matlab::data::ArrayFactory, which you use to produce
matlab::data::Arrayobjects that you pass into function calls.
For each library that you initialize, call
initMATLABLibrary, which takes two parameters:
Copy of the
shared_ptrthat was returned by
Path to the archive (
To call a function in an initialized library, call
unique_ptrthat was returned by
initMATLABLibrary. There are several overloaded versions of each. They all take the name of the MATLAB function as the first parameter. However, these differ in terms of whether they accept and return single
matlab::data::Arrayobjects, arrays of
matlab::data::Array, or native types. The forms that return a native type must take the type as a template parameter.
To terminate a library, either call
unique_ptr, or allow it to go out of scope.
To terminate the application, either call
shared_ptr, or allow it to go out of scope. It does not terminate until all the libraries created underneath it have been terminated or gone out of scope.
For example code that uses the C++ MATLAB Data Array API, see
matrix_mda.cpp located in