Main Content

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 SystemVariablePath

Windows®

PATH

matlabroot\extern\bin\win64

macOS with Apple silicon

DYLD_LIBRARY_PATH

matlabroot/extern/bin/maca64

macOS with Intel®

DYLD_LIBRARY_PATH

matlabroot/extern/bin/maci64

Linux®

LD_LIBRARY_PATH

matlabroot/extern/bin/glnxa64:matlabroot/sys/os/glnxa64

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

|

Related Topics