mex
Build MEX function or engine application
Syntax
Description
mex
compiles and links one
or more C++ source files written with the MATLAB Data API for C++ into a binary MEX file in the
current folder. For information about writing these applications, see Write C++ Functions Callable from MATLAB (MEX Files).filenames
If writing MEX files based on the C Matrix API or the Fortran Matrix API, then mex
builds one or more C,
C++, or Fortran source files with the filenames
-R2017b
api
. In a future version of MATLAB®, the default api
option will change to use the
interleaved complex API (-R2018a
). MathWorks recommends that
you create MEX files and update existing MEX files to use the interleaved
complex API. Alternatively, use the
MX_HAS_INTERLEAVED_COMPLEX
macro to ensure the desired
behavior across versions of MATLAB. For more information, see MATLAB Support for Interleaved Complex API in MEX Functions.
For information about working with C, C++, and Fortran applications, see Integrate MATLAB with External Programming Languages and Systems.
mex
builds with the specified filenames
api
option1 ... optionN
api
and optional
option1 ... optionN
arguments. The option1
... optionN
arguments supplement or override the default
mex
build configuration.
mex -client engine
builds
C++ source files written with the MATLAB Data API for C++ into standalone MATLAB engine applications. For more information, see Introduction to Engine API for C++filenames
If writing applications based on the MATLAB
Engine API for C, the C
MAT-File API, the Fortran Engine API, or the Fortran MAT-File API, then mex -client engine
builds a standalone
application with the filenames
-R2017b
api
. In a future version of MATLAB, the default api
option will change to use the
interleaved complex API (-R2018a
). MathWorks recommends that
you create engine applications and update existing applications to use the
interleaved complex API.
mex -client engine
builds engine applications with the specified filenames
api
option1 ... optionN
api
and
optional option1 ... optionN
arguments.
mex -setup [
displays
information about the default compiler for the given language for building MEX
files. MATLAB defines a default compiler for each supported language. If you
have multiple compilers for a given language, use the lang
]lang
option to change the default compiler for that language. For more information,
see Change Default Compiler and
Choose a C++ Compiler.
mex -setup -client engine [
selects a compiler for building engine applications.lang
]
Examples
Input Arguments
Tips
You can run
mex
from:MATLAB Command Window
Windows system prompt
macOS Terminal
Linux shell
For command-line usage outside of MATLAB, the
mex
program is located in the folder specified by[matlabroot '/bin']
on UNIX and[matlabroot '\bin\win64']
on Windows.The MEX file has a platform-dependent extension. You can place binary MEX files for different platforms in the same folder. To identify the MEX file extension, use the
mexext
function.MEX File Platform-Dependent Extension
Platform Binary MEX File Extension Linux (64-bit)
mexa64
Apple Mac (64-bit)
mexmaci64
Windows (64-bit)
mexw64
To use
mex
to build executable files for standalone MATLAB engine applications, use the-client engine
option.The
mex
command does not support folder names containing double quote ("
) characters.