Main Content

Requirements to Build C++ Engine Programs

Supported Compilers

Use a compiler that supports C++11. For an up-to-date list of supported compilers, see Supported and Compatible Compilers.

Build with mex Command

You can use the MATLAB® Editor to write your engine application code and run the mex command to build it. To set up the compiler for C++ engine applications, type:

mex -setup -client engine C++

To build your C++ engine program MyEngineCode.cpp, type:

mex -client engine MyEngineCode.cpp 

To test your setup, see Test Your C++ Build Environment.

Build with IDE

To use an integrated development environment (IDE) such as Microsoft® Visual Studio® or Xcode to write your source code, set up your environment for building C++ engine applications using the following libraries and include files. Engine applications require the engine library libMatlabEngine, the MATLAB Data Array library libMatlabDataArray, and supporting include files.

In the following path specifications, replace matlabroot with the path returned by the MATLAB matlabroot command.

Windows Libraries

In these path specifications, replace compiler with either microsoft or mingw64.

  • Engine library — matlabroot\extern\lib\win64\compiler\libMatlabEngine.lib

  • MATLAB Data Array library — matlabroot\extern\lib\win64\compiler\libMatlabDataArray.lib

macOS Libraries

  • Engine library — matlabroot/extern/bin/maci64/libMatlabEngine.dylib

  • MATLAB Data Array library — matlabroot/extern/bin/maci64/libMatlabDataArray.dylib

Linux Libraries

  • Engine library — matlabroot/extern/bin/glnxa64/

  • MATLAB Data Array library — matlabroot/extern/bin/glnxa64/

Additional library — pthread

For example, to build myEngineApp.cpp, use these libraries. Replace matlabroot with the path returned by the MATLAB matlabroot command.

g++ -std=c++11 -I matlabroot/extern/include/ -L matlabroot/extern/bin/glnxa64/ 
    -pthread myEngineApp.cpp -lMatlabDataArray -lMatlabEngine

Engine Include Files

Header files contain function declarations with prototypes for the routines that you access in the API libraries. These files are in the matlabroot/extern/include folder and are the same for Windows®, macOS, and Linux® systems. Engine applications use:

  • MatlabEngine.hpp — Definitions for the C++ Engine API

  • MatlabDataArray.hpp — Definitions for a generic interface between C++ and MATLAB data

The MATLAB data array is a collection of classes and APIs that .

Run-Time Environment

To run your application, set one of these environment variables to the specified path.

Operating SystemVariablePath










See Also


Related Topics