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

Replace macos with either maca64 for macOS with Apple silicon or maci64 for macOS with Intel®.

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

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

Linux Libraries

  • Engine library — matlabroot/extern/bin/glnxa64/libMatlabEngine.so

  • MATLAB Data Array library — matlabroot/extern/bin/glnxa64/libMatlabDataArray.so

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 provides a generic interface between external data and MATLAB.

Run-Time Environment

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

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

See Also

|

Related Topics