Main Content

Deploy to C++ Applications Using MATLAB Data API

Integrate packaged MATLAB® functions into C++ applications using the MATLAB Data API for data exchange

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++.

Functions C++ shared library for building C++ shared libraries
mbuildCompile and link source files against MATLAB generated shared libraries
mccCompile MATLAB functions for deployment


matlab::cpplib::initMATLABApplicationStart the MATLAB Runtime and initialize its application state
matlab::cpplib::runMainExecute a function with its input arguments within the main function
matlab::cpplib::convertUTF8StringToUTF16StringConvert UTF-8 string to UTF-16 string
matlab::cpplib::convertUTF16StringToUTF8StringConvert UTF-16 string to UTF-8 string
matlab::cpplib::initMATLABLibraryInitialize a library of MATLAB functions packaged in a deployable archive file
matlab::cpplib::initMATLABLibraryAsyncInitialize a library of MATLAB function asynchronously
matlab::cpplib::MATLABLibrary::fevalExecute a MATLAB function from a deployable archive
matlab::cpplib::MATLABLibrary::fevalAsyncExecute a MATLAB function from a deployable archive asynchronously
matlab::cpplib::MATLABLibrary::waitForFiguresToCloseWait for all figures to close



Create and Integrate

Integrate a C++ Shared Library with C++ Application


Strongly Typed Interface