Deploy to C++ Applications Using mwArray
API
(C++03)
mwArray
API for data exchangeIn 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
compiler.build.cppSharedLibrary | Create C++ shared library (Since R2021a) |
compiler.build.CppSharedLibraryOptions | Options for building C++ shared libraries (Since R2021a) |
compiler.build.Results | Compiler build results object (Since R2020b) |
mbuild | Compile and link source files against MATLAB generated shared libraries |
C/C++ API
mclmcrInitialize | Initialize the MATLAB Runtime proxy library |
mclInitializeApplication | Set up application state shared by all MATLAB Runtime instances created in current process |
mclTerminateApplication | Close MATLAB Runtime-internal application state |
<library>Initialize[WithHandlers] | Initialize MATLAB Runtime instance associated with
|
<library>Terminate | Free all resources allocated by MATLAB Runtime instance associated with
|
mclRunMain | Mechanism for creating identical wrapper code across all platforms |
mclIsMCRInitialized | Determine if MATLAB Runtime has been properly initialized |
mclWaitForFiguresToDie | Enable deployed applications to process graphics events so that figure windows remain displayed |
mclGetLastErrorMessage | Last error message from unsuccessful library initialization or MATLAB function call |
mclGetLogFileName | Retrieve name of log file used by MATLAB Runtime |
mclIsJVMEnabled | Determine if MATLAB Runtime was started with instance of Java Virtual Machine (JVM) |
mclIsNoDisplaySet | Determine if -nodisplay mode is enabled |
C++ mwArray API
mwArray | Class used to pass input/output arguments to C++ functions generated by MATLAB Compiler SDK |
mwException | Exception type used by the mwArray API
and the C++ interface functions |
mwString | String class used by the mwArray API
to pass string data as output from certain methods |
Topics
Requirements
- MATLAB Compiler SDK C++ Target Requirements
Review the software requirements for using MATLAB Compiler SDK to deploy MATLAB functions to C++ applications. - Set Up C++ Development Environment
Set up development environment to develop C++ applications that integrate deployed MATLAB functions.
Create C++ mwArray
API Shared Library
- Generate a C++ mwArray API Shared Library and Build a C++ Application
Create a C++ mwArray API shared library from MATLAB code and implement it with sample C++ driver code.
Integrate C++ Shared Library into C++ Application
- Call MATLAB Compiler SDK API Functions from C/C++
Use MATLAB Compiler SDK shared library functions in C and C++ code. - Integrate C++ Shared Libraries with mwArray
Write C++ code to reference shared libraries that use themwArray
API. - Create Sample Code to Call Exported Function
Generate sample code in C++, .NET, Java®, or Python® by including sample files during packaging. - Configure the mbuild Options File
How to configure thembuild
options file. - Use Multiple Shared Libraries in Single Application
Use multiple generated shared libraries in a single C/C++ application.
Maintenance
- 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,mclmcrrt
. - Compilation Failures
List of possible failures during compilation. - Testing Failures
List of possible failures during testing. - Deployment Failures
List of possible failures during deployment.