Build C++ Engine Programs

Supported Compilers

Use compilers that support C++11. For an up-to-date list of supported compilers, see the Supported and Compatible Compilers website.

Build .cpp File with mex Command

If you have installed one of the supported compilers, set up the compiler for C++ engine applications using the mex command. When provided with an option to select a compiler, select an installed compiler that the MATLAB® Engine API for C++ supports.

mex -setup -client engine C++

Build your C++ engine program using the MATLAB mex command.

mex -client engine MyEngineCode.cpp 

To test your setup, see Test Your Build Environment .

General Requirements

Set up your environment for building and running C++ engine applications using these libraries, include files, environment variables. Engine applications require the engine library libMatlabEngine, the MATLAB Data Array library libMatlabDataArray, and supporting include files.

In the following sections, 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

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

Mac Libraries

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

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

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®, Mac, and Linux® systems. Engine applications use:

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

  • MatlabDataArray.hpp — Definitions for MATLAB Data Arrays

MATLAB Data Array is a collection of classes and APIs that provide a generic interface between external data and MATLAB.

Runtime Environment

This table lists the names of the environment variables and the paths to add for the respective platforms.

Operating SystemVariablePath

Windows

PATH

matlabroot\extern\bin\win64

64-bit Apple Mac

DYLD_LIBRARY_PATH

matlabroot/extern/bin/maci64

64-bit Linux

LD_LIBRARY_PATH

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

See Also

|

Related Topics