Deploy to C++ Applications Using MATLAB Data API (C++11)
In this approach, you use functionality in MATLAB
Compiler SDK™ to generate a code archive (.ctf
file)
containing MATLAB functions, along with a header (.hpp
file) that establishes a mapping between MATLAB and C++ data types. Integrate these within your C++
application.
Use MATLAB Compiler SDK API for C++ as an interface between the C++ application and the code archive containing the deployed MATLAB functions. Use the MATLAB Data API to handle data exchange between the C++ application and deployed MATLAB functions. For details on data exchange, see MATLAB Data API for C++.
To ensure that this is the right approach for you, see Choose C++ Deployment Option.
MATLAB Runtime must be installed and set up on the machine running the C++ application. For details, see Download and Install MATLAB Runtime.
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 |
mcc | Compile MATLAB functions for deployment |
C/C++ API
matlab::cpplib::initMATLABApplication | Start the MATLAB Runtime and initialize its application state |
matlab::cpplib::runMain | Execute a function with its input arguments within the main function |
matlab::cpplib::convertUTF8StringToUTF16String | Convert UTF-8 string to UTF-16 string |
matlab::cpplib::convertUTF16StringToUTF8String | Convert UTF-16 string to UTF-8 string |
matlab::cpplib::initMATLABLibrary | Initialize a library of MATLAB functions packaged in a deployable archive file |
matlab::cpplib::initMATLABLibraryAsync | Initialize a library of MATLAB function asynchronously |
matlab::cpplib::MATLABLibrary::feval | Execute a MATLAB function from a deployable archive |
matlab::cpplib::MATLABLibrary::fevalAsync | Execute a MATLAB function from a deployable archive asynchronously |
matlab::cpplib::MATLABLibrary::waitForFiguresToClose | Wait for all figures to close |
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. - Download and Install MATLAB Runtime
Install, configure, and uninstall MATLAB Runtime. - Choose C++ Deployment Option
Explore C++ deployment options that MATLAB Compiler SDK offers and select the right one for your specific C++ integration needs. - Summary of MATLAB Compiler SDK C++ APIs
Explore the various MATLAB Compiler SDK C++ APIs.
Create and Integrate
- Deploy MATLAB Function to C++ Application Using MATLAB Data API
Learn how to deploy a MATLAB function to C++ application using the MATLAB Data API. - Deploy MATLAB Classes to C++ Application Using MATLAB Data API
Learn how to deploy MATLAB classes contained in a package to a C++ application using the MATLAB Data API. - Deploy MATLAB Class That Inherits from MATLAB Handle Class
Learn how to package and deploy a MATLAB class that inherits from the MATLAB handle class to a C++ application. (Since R2024a) - Deploy MATLAB Function That Accepts Struct Array as Input Argument
Learn how to package and deploy a MATLAB function that accepts a struct array as input to an application written in C++. - Pass C++ Structures to Deployed MATLAB Functions
Learn how to pass C++ structures to deployed MATLAB functions. (Since R2024b) - Code Archive (.ctf file) Placement
Explore various options for positioning the code archive (.ctf
file) in an accessible location prior to running the executable.
Data Type Mapping and Sample Generation
- 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. - Map MATLAB Classes and Functions to C++
Learn how MATLAB classes and function map to a C++ header file when deployed using the MATLAB Data API. - Work with MATLAB Structure Arrays
Learn how to handle MATLAB structs in C++ code when deploying MATLAB functions that accept struct arrays as input arguments and return them as output. (Before R2024b) - Create Sample Code to Call Exported Function
Generate sample code in C++, .NET, Java®, or Python® by including sample files during packaging.
More Code Samples
- Call MATLAB Compiler SDK API Functions from C/C++
Use MATLAB Compiler SDK shared library functions in C and C++ code. - 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++ 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. - 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.
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
. - Troubleshoot mbuild
Issues involving thembuild
utility and creating standalone applications.