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
with the path returned by the MATLAB
matlabroot
matlabroot
command.
Windows Libraries
In these path specifications, replace compiler
with either microsoft
or mingw64
.
Engine library —
matlabroot
\extern\lib\win64\compiler
\libMatlabEngine.libMATLAB Data Array library —
matlabroot
\extern\lib\win64\compiler
\libMatlabDataArray.lib
Linux Libraries
Engine library —
matlabroot
/extern/bin/glnxa64/libMatlabEngine.soMATLAB 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
Mac Libraries
Engine library —
matlabroot
/extern/bin/maci64/libMatlabEngine.dylibMATLAB 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
folder and are the same for Windows®, Mac, and Linux® systems. Engine applications use:matlabroot
/extern/include
MatlabEngine.hpp
— Definitions for the C++ engine APIMatlabDataArray.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 System | Variable | Path |
---|---|---|
Windows |
|
|
64-bit Apple Mac |
|
|
64-bit Linux |
|
|
See Also
mex
| matlab::engine::MATLABEngine