Requirements to Build C++ Engine Applications
MATLAB® includes the engine and data APIs you need to work with MATLAB code and data in C++ programs. Additionally, you need to install a supported compiler, configure MATLAB to use the compiler, and configure your run-time environment. To set up your C++ development environment, see Set Up C++ Development Environment.
MATLAB Engine and Data APIs
MATLAB provides APIs for working with MATLAB in C++ programs. These APIs are installed on your system when you install MATLAB.
MATLAB Engine API for C++ — With this API, your C++ program can interact with MATLAB synchronously or asynchronously. For the complete API, see Call MATLAB from C++.
MATLAB Data API for C++ — Use this API to handle the data exchange between MATLAB and C++. The API is in the
matlab::data
namespace. For more information, see MATLAB Data API for C++.
Supported Compilers
Install a compiler that supports C++11. For an up-to-date list of supported compilers, see Supported and Compatible Compilers on the MathWorks® website.
Build with mex
Command
If you use the MATLAB Editor to write your C++ application code, then you can configure and
run the mex
command to build it. This
command sets up the compiler for C++ applications.
mex -setup -client engine C++
This command builds your C++ application
MyEngineCode.cpp
.
mex -client engine MyEngineCode.cpp
Run-Time Environment
To run your application, configure your run-time environment by adding one of
these environment variables to the specified path. When specifying these paths,
replace matlabroot
with the path returned by the
MATLAB
matlabroot
command.
Operating System | Variable | Path |
---|---|---|
Windows® |
|
|
macOS with Apple silicon |
|
|
macOS with Intel® |
|
|
Linux® |
|
|
For example, if your matlabroot
on Windows is C:\Program Files\MATLAB\R2024b
, then this system
prompt command sets the run-time environment variable:
set PATH=C:\Program Files\MATLAB\R2024b\extern\bin\win64;%PATH%
See Also
mex
| matlab::engine::MATLABEngine