Build your C++ MEX application using the MATLAB®
mex
to set up your environment and compile the C++ source code.
Use compilers that support C++11. For an up-to-date list of supported compilers, see the Supported and Compatible Compilers website.
mex
CommandIf you have installed one of the supported compilers, set up the compiler for C++ MEX applications using the mex
command. When provided with an option to select a compiler, select an installed compiler that the MATLAB C++ MEX supports.
mex -setup C++
Build your C++ MEX program using the MATLAB
mex
command.
mex MyMEXCode.cpp
Include the following header files in your C++ source code. 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. C++ MEX files use these header files:matlabroot
/extern/include
mex.hpp
— Definitions for the C++ MEX API
mexAdapter.hpp
— Utilities required by the C++ MEX function
operator
Note
Include mexAdapter.hpp
only once with the MexFunction
class definition in MEX applications that span multiple files.
MEX files are platform-specific. MATLAB identifies MEX files by platform-specific extensions. The following table lists the platform-specific extensions for MEX files.
MEX File Platform-Dependent Extension
Platform | Binary MEX File Extension |
---|---|
Linux (64-bit) |
|
Apple Mac (64-bit) |
|
Windows (64-bit) |
|
matlab::engine::MATLABEngine
| mex