Build MEX function or engine application
mex
compiles and links one
or more C++ source files written with the MATLAB Data API into a binary MEX file in the
current folder. For information about writing these applications, see C++ MEX Applications.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 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
MATLAB C API to Read MAT-File Data, the
MATLAB Engine API for Fortran, or
the MATLAB Fortran API to Read MAT-File Data,
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
]
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) |
|
Apple Mac (64-bit) |
|
Windows (64-bit) |
|
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.
clear
| computer
| dbmex
| inmem
| loadlibrary
| mexext
| pcode
| prefdir
| system