Main Content

Summary of MATLAB Compiler SDK C++ APIs

MATLAB® Compiler SDK™ provides two ways to deploy MATLAB functions within C++. Each deployment option has a set of C++ APIs that enable deployment. You can:

  • Deploy to C++ Applications using MATLAB Data API (C++11)

    • Application Interface: MATLAB Compiler SDK C++ API with two options:

      • Generic Interface (since R2018a)

      • Strongly Typed Interface (since R2021b)

    • Data Interface: MATLAB Data API (C++11)

  • Deploy to C++ Applications using mwArray API (C++03)

    • Application Interface: MATLAB Compiler SDK C++ API

    • Data Interface: mwArray API

Deploy to C++ Applications Using MATLAB Data API (C++11)

Generic Interface (since R2018a)

  • In this approach, you create a code archive (.ctf file) containing MATLAB functions and deploy it within a C++ application.

  • You use the MATLAB Compiler SDK API for C++ as an interface between the C++ application and the code archive containing the deployed MATLAB functions.

  • You use the MATLAB Data API to handle data exchange between the C++ application and deployed MATLAB functions. The MATLAB Data API provides modern C++11 features not available with the mwArray API, which only uses C++03 features. Specifically, the MATLAB Data API allows data to be moved instead of copied when possible, automatically manages resource cleanup, and minimizes the number of copy operations. This efficient data handling enhances the exchange between the C++ application and deployed MATLAB functions.

Strongly Typed Interface (since R2021b)

  • In this approach, you create a code archive (.ctf file) containing MATLAB functions and generate a corresponding header file (.hpp file) that establishes a predefined mapping between C++ and MATLAB data types. You deploy these artifacts within a C++ application.

  • The interface allows you to define a contract specifying how MATLAB should interpret and manage C++ data types. To create this contract, you can use an arguments block in a MATLAB function, or a combination of properties and arguments blocks in a MATLAB class. For instance, if your C++ application employs a uint32 data type representing a real scalar value, you would define this in your MATLAB code as (1,1) uint32 {mustBeReal}.

  • Also, C++ namespaces, classes, and public methods align with their MATLAB counterparts, maintaining consistent naming and eliminating the need for intermediate top-level functions.

Note

Regarding the deployment process, deploying to a strongly typed interface mirrors the procedure for deploying to a generic interface quite closely. The sole distinction lies in the MATLAB function under deployment—it requires modification to reflect the MATLAB equivalent of the C++ types.

Deploy to C++ Applications Using mwArray API (C++03)

In this approach, you create a C++ shared library and header file from MATLAB functions you want to deploy. Use the legacy MATLAB Compiler SDK API for C++ as an interface between the C++ application and the deployed MATLAB functions. Use the mwArray API to handle data exchange between the C++ application and the deployed MATLAB functions. The mwArray API is uses C++03 constructs.

Related Topics