Use compilers that support C++11. For an up-to-date list of supported compilers, see the Supported and Compatible Compilers website.
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 .
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
with the path returned by the MATLAB
matlabroot
matlabroot
command.
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
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
with the path returned by the MATLAB
matlabroot
matlabroot
command.
g++ -std=c++11 -I <matlabroot>/extern/include/ -L <matlabroot>/extern/bin/glnxa64/ -pthread myEngineApp.cpp -lMatlabDataArray -lMatlabEngine
Engine library —
matlabroot
/extern/bin/maci64/libMatlabEngine.dylib
MATLAB Data Array library —
matlabroot
/extern/bin/maci64/libMatlabDataArray.dylib
Header files contain function declarations with prototypes for the routines that you access in the API libraries. These files are in the
folder and are the same for Windows®, Mac, and Linux® systems. Engine applications use:matlabroot
/extern/include
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.
This table lists the names of the environment variables and the paths to add for the respective platforms.
Operating System | Variable | Path |
---|---|---|
Windows |
|
|
64-bit Apple Mac |
|
|
64-bit Linux |
|
|
matlab::engine::MATLABEngine
| mex