Main Content

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

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

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. You must include the generated header file in your C++ application using a preprocessor directive for the deployed MATLAB functions to be available as member functions within your C++ code. You need to explicitly manage the life-cycle of the MATLAB Runtime instance used by the deployed MATLAB functions. The runtime instance can be run only in-process with the C++ application and deployed MATLAB functions can be executed only synchronously.

The C++ mwArray API supports only C++03 functionality. C++ shared libraries that use the mwArray API have an interface that uses C-style functions to initialize the MATLAB Runtime, load the packaged MATLAB functions into the MATLAB Runtime, and manage data that is passed between the C++ driver code and MATLAB Runtime. These functions are described under C/C++ API. The functions listed under C++ mwArray API are specific to the mwArray API and cannot be used for shared libraries created for other APIs.

Functions C++ shared library (Since R2021a) for building C++ shared libraries (Since R2021a) build results object (Since R2020b)
mbuildCompile and link source files against MATLAB generated shared libraries


mclmcrInitializeInitialize the MATLAB Runtime proxy library
mclInitializeApplicationSet up application state shared by all MATLAB Runtime instances created in current process
mclTerminateApplicationClose MATLAB Runtime-internal application state
<library>Initialize[WithHandlers]Initialize MATLAB Runtime instance associated with library
<library>TerminateFree all resources allocated by MATLAB Runtime instance associated with library
mclRunMainMechanism for creating identical wrapper code across all platforms
mclIsMCRInitializedDetermine if MATLAB Runtime has been properly initialized
mclWaitForFiguresToDieEnable deployed applications to process graphics events so that figure windows remain displayed
mclGetLastErrorMessageLast error message from unsuccessful library initialization or MATLAB function call
mclGetLogFileNameRetrieve name of log file used by MATLAB Runtime
mclIsJVMEnabledDetermine if MATLAB Runtime was started with instance of Java Virtual Machine (JVM)
mclIsNoDisplaySetDetermine if -nodisplay mode is enabled

C++ mwArray API

mwArrayClass used to pass input/output arguments to C++ functions generated by MATLAB Compiler SDK
mwExceptionException type used by the mwArray API and the C++ interface functions
mwStringString class used by the mwArray API to pass string data as output from certain methods



Create C++ mwArray API Shared Library

Integrate C++ Shared Library into C++ Application