Deploy to C++ Applications Using MATLAB Data API
To deploy MATLAB functions to C++ applications, you create an archive containing MATLAB functions using MATLAB Compiler SDK™ and include it within a C++ application. Starting in R2018a, use the MATLAB Compiler SDK API for C++ as an interface between the C++ application and the archive containing the deployed MATLAB functions. Use the MATLAB Data API to handle data exchange between the C++ application and deployed MATLAB functions. Some advantages of the approach are:
You do not need to explicitly manage the life-cycle of the MATLAB Runtime instance and library of MATLAB functions in the archive since the C++ API provides a fail-safe way to terminate them.
The runtime instance can run either in-process or out-of-process with respect to the C++ application, and deployed MATLAB functions can be executed either synchronously or asynchronously.
The C++ API supports C++11 functionality, type-safety, and multi-thread-safety.
Starting in R2021b, you can you can stipulate how to represent MATLAB data types in C++ application code by using standard and custom data type mappings between MATLAB and C++.
MATLAB Runtime must be installed and setup on the machine running the C++ application.
For additional details, see MATLAB Data API for C++.
|Create C++ shared library|
|Options for building C++ shared libraries|
|Compile and link source files against MATLAB generated shared libraries|
|Compile MATLAB functions for deployment|
|Start the MATLAB Runtime and initialize its application state|
|Execute a function with its input arguments within the main function|
|Convert UTF-8 string to UTF-16 string|
|Convert UTF-16 string to UTF-8 string|
|Initialize a library of MATLAB functions packaged in a deployable archive file|
|Initialize a library of MATLAB function asynchronously|
|Execute a MATLAB function from a deployable archive|
|Execute a MATLAB function from a deployable archive asynchronously|
|Wait for all figures to close|
- MATLAB Compiler SDK C++ Target Requirements
Refer to the software requirements for using MATLAB Compiler SDK to deploy MATLAB functions to C++ applications.
- C++ Development Environment
Set up development environment to develop C++ applications that integrate deployed MATLAB functions.
Create and Integrate
- Generate a C++ MATLAB Data API Shared Library and Build a C++ Application
Create a C++ MATLAB Data API shared library from MATLAB code and integrate it with sample C++ driver code.
- Create C/C++ Shared Libraries from Command Line
Use the command-line compiler to create C/C++ shared libraries.
Integrate a C++ Shared Library with C++ Application
- Integrate C++ Shared Libraries with MATLAB Data API
Write C++ code to reference shared libraries that use the MATLAB Data API.
- Call MATLAB Compiler SDK API Functions from C/C++
Use MATLAB Compiler SDK shared library functions in C and C++ code.
- Configure the mbuild Options File
How to configure the
- Write Applications for macOS
Write deployable C++ applications specifically for macOS.
Strongly Typed Interface
- C++ MATLAB Data API Shared Library Support for Strongly Typed MATLAB Code
Learn how a C++ MATLAB Data API shared library supports using strongly typed MATLAB code.
- Create C++ MATLAB Data API Shared Library Header from Strongly Typed MATLAB Function
Create a C++ MATLAB Data API shared library from a strongly typed MATLAB function and integrate it with sample C++ application code.
- Create C++ MATLAB Data API Shared Library Header from Strongly Typed MATLAB Classes Contained in Package
Create a C++ MATLAB Data API shared library from strongly typed MATLAB class contained in a package and integrate it with sample C++ application code.
- Data Type Mappings Between C++ and Strongly Typed MATLAB Code
Refer to data type mappings between C++ and MATLAB when using strongly typed MATLAB code.
- Memory Management and Cleanup
See recommendations on memory management.
- Understand the mclmcrrt Proxy Layer
All application and software components generated by MATLAB Compiler™ and MATLAB Compiler SDK need to link against only one MATLAB library,
- Troubleshoot mbuild
Issues involving the
mbuildutility and creating standalone applications.