C++ Development Environment
To integrate MATLAB® functions within C++ applications you need to set up your C++ development environment.
You can use the MATLAB desktop to create your deployable MATLAB functions, write C++ application code, and integrate the two. The MATLAB desktop environment can be used across platforms.
On Windows® systems, you can use Microsoft® Visual Studio® as your development environment.
Prerequisite
Write MATLAB functions you want to deploy.
Use the
compiler.build.cppSharedLibrary
function to create deployable MATLAB functions.
Set Up MATLAB Desktop for C++ Development (Windows, Linux, and macOS)
At the MATLAB command prompt, configure a C++ compiler for use with your C++ application by executing:
mbuild -setup
Use the MATLAB Editor to author the C++ application code.
Use the
mbuild
function to compile and link C++ application code against deployable MATLAB functions.mbuild <cppApplicationSourceCode>.cpp -v (MATLAB Data API) mbuild <cppApplicationSourceCode>.cpp <compilerSDKGeneratedLibrary>.lib -v (mwArray API)
Set Up Microsoft Visual Studio for C++ Development (Windows Only)
Create a new C++ project in Visual Studio. Select Console App if you are creating a C++ console application. Otherwise, pick the appropriate project type.
Access project properties by right-clicking the project node in Solution Explorer and choosing Properties.
Verify that the Platform is set to
x64
in the project property page.In the left pane of the project property page, under C/C++ > General, add the following directories to the Additional Include Directories field:
C:\Program Files\MATLAB\MATLAB Runtime\R2023a\extern\include
Under Linker > General, add the following directories to the Additional Library Directories field:
C:\Program Files\MATLAB\MATLAB Runtime\R2023a\extern\lib\win64\microsoft
Under Linker > Input, add the following libraries:
In the Additional Dependencies field, add:
delayimp.lib libMatlabCppSharedLib.lib libMatlabDataArray.lib
In the Delay Loaded Dlls field, add:
libMatlabDataArray.dll
Include the following header file in your C++ application code:
#include "MatlabCppSharedLib.hpp"
Other Development Environments
In order to use other C++ development environments, you need to know which
additional files and libraries to include during compilation. It is recommended
that you first compile your C++ application using the mbuild
function in
MATLAB using the verbose mode. This will display all the information you
need to include other development environments.
Location of Relevant Files
Windows | MATLAB
MATLAB Runtime
|
Linux® | MATLAB
MATLAB Runtime
|
macOS | MATLAB
MATLAB Runtime
|