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 apply 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 Structure of C++ Engine Applications.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
Build MEX File Using Interleaved Complex API
Copy the source code example from the
matlabroot/extern/examples
folder.
copyfile(fullfile(matlabroot,'extern','examples','mex','explore.c'),'.','f')
Build the MEX file. The output displays information specific to your compiler.
mex -R2018a explore.c
Test the function by passing complex matrices.
a = [1 3 5]; b = [5 3 1]; A = complex(a,b); explore(A)
------------------------------------------------ Name: prhs[0] Dimensions: 1x3 Class Name: double ------------------------------------------------ (1,1) = 1 + 5i (1,2) = 3 + 3i (1,3) = 5 + 1i
Build C MEX File
Build a single C program yprime.c
into a MEX file.
Copy the source code example from the matlabroot
/extern/examples
folder.
copyfile(fullfile(matlabroot,"extern","examples","mex","yprime.c"),".","f")
Build the MEX file. The output displays information specific to your compiler.
mex yprime.c
Building with 'Microsoft Visual C++ 2019 (C)'. MEX completed successfully.
Test.
T=1; Y=1:4; yprime(T,Y)
ans = 1×4
2.0000 8.9685 4.0000 -1.0947
Display Detailed Build and Troubleshooting Information
To display the compile and link commands and other information useful for troubleshooting, use verbose mode. The output displays information specific to your platform and compiler.
mex -v -compatibleArrayDims yprime.c
Append Compiler Options
Use environment variables to specify additional options to pass to a compiler.
Determine the variable name:
For building C++ code with MinGW®, macOS, and Linux® compilers, use
CXXFLAGS
.For building C code with MinGW, macOS, and Linux compilers, use
CFLAGS
.With Microsoft® Visual Studio® compilers, use
COMPFLAGS
.
Specify the C++17 standard when building a MEX file with Visual Studio.
mex COMPFLAGS="$COMPFLAGS /std:c++17" yprime.c
For more information about using string delimiters on different platforms, see Override Default Compiler Switch Option.
Override Default Compiler Switch Option
Build the yprime.c
MEX file by appending
the value -Wall
to the existing compiler flags. Because the
value includes a space character, you must delineate the string; the character
you use depends on the platform.
At the MATLAB prompt, use single quotes ('
).
mex -v COMPFLAGS='$COMPFLAGS -Wall' yprime.c
For the MinGW-w64 compiler, which is based on gcc/g++, use the Linux compiler flags. Choose one of these commands:
mex -v CXXFLAGS='$CXXFLAGS -Wall' yprime.c % C++ compiler mex -v CFLAGS='$CFLAGS -Wall' yprime.c % C compiler
At the Windows® command prompt, use double quotes
("
).
mex -v COMPFLAGS="$COMPFLAGS -Wall" yprime.c
At the shell command line on macOS and Linux, use single quotes ('
).
mex -v CFLAGS='$CFLAGS -Wall' yprime.c
Build MEX File from Multiple Source Files
The MEX file example fulltosparse
consists of two Fortran source files, loadsparse.F
and fulltosparse.F
. To run this example, you need a supported Fortran compiler installed on your system.
Copy the source files to the current folder.
copyfile(fullfile(matlabroot,'extern','examples','refbook','loadsparse.F'),'.','f') copyfile(fullfile(matlabroot,'extern','examples','refbook','fulltosparse.F'),'.','f')
Build the fulltosparse
MEX file. The MEX file name is fulltosparse
because fulltosparse.F
is the first file on the command line. The output contains information specific to your compiler.
mex -largeArrayDims fulltosparse.F loadsparse.F
Building with 'Intel Visual Fortran Composer XE 2013 with Microsoft Visual Studio 2012'. MEX completed successfully.
Test.
full = eye(5); spar = fulltosparse(full)
spar = 1,1 1 2,2 1 3,3 1 4,4 1 5,5 1
Combine Source Files Using Wild Card
Combine all C source files in the current folder into MEX
file mymex
. Use the -output
option to
control the name of the MEX file.
mex -output mymex *.c
Preview Build Commands
To preview the build command details without executing the
commands, use the -n
option. The output displays information
specific to your platform and compiler.
mex -n yprime.c
Create and Link to Separate Object Files
You can link to object files that you compile separately from your source MEX files.
The MEX file example fulltosparse consists of two Fortran source files. The fulltosparse
file is the gateway routine (contains the mexFunction
subroutine) and loadsparse
contains the computational routine.
To run this example, you need a supported Fortran compiler installed on your system. Copy the computational subroutine to your current folder.
copyfile(fullfile(matlabroot,'extern','examples','refbook','loadsparse.F'),'.','f')
Compile the subroutine and place the object file in a separate folder, c:\objfiles
.
mkdir c:\objfiles mex -largeArrayDims -c -outdir c:\objfiles loadsparse.F
Building with 'Intel Visual Fortran Composer XE 2013 with Microsoft Visual Studio 2012'. MEX completed successfully.
Copy the gateway subroutine to your current folder. Compile and link with the loadsparse
object file.
copyfile(fullfile(matlabroot,'extern','examples','refbook','fulltosparse.F'),'.','f') mex -largeArrayDims fulltosparse.F c:\objfiles\loadsparse.obj
Building with 'Intel Visual Fortran Composer XE 2013 with Microsoft Visual Studio 2012'. MEX completed successfully.
Specify Path to Include File
To specify the path to include the MATLAB LAPACK library subroutines for handling complex number routines,
use the -I
option. To use these subroutines, your MEX file
must access the header file fort.h
.
Copy the matrixDivideComplex.c
example to the current
folder.
copyfile(fullfile(matlabroot,'extern','examples','refbook','matrixDivideComplex.c'),'.','f')
Create the -I
argument by concatenating
'-I'
with the path to the fort.h
file.
ipath = ['-I' fullfile(matlabroot,'extern','examples','refbook')];
Create variables for the names and paths to the LAPACK library file and
the file, fort.c
, containing the complex number handling
routines.
lapacklib = fullfile(matlabroot,'extern','lib',computer('arch'),'microsoft','libmwlapack.lib'); fortfile = fullfile(matlabroot,'extern','examples','refbook','fort.c');
Build the MEX file.
mex('-v','-R2017b',ipath,'matrixDivideComplex.c',fortfile,lapacklib)
Specify Path to Library File
Build the matrixDivide.c
example on a
Windows platform using the -L
and -l
options to specify the libmwlapack.lib
library. The library
file is located in the folder
.matlabroot
\extern\lib\arch
\microsoft
Copy the matrixDivide.c
example to the current
folder.
copyfile(fullfile(matlabroot,'extern','examples','refbook','matrixDivide.c'),'.','f')
Capture the value of matlabroot
displayed by
this statement to use in the mex
command.
matlabroot
ans = C:\Program Files\MATLAB\R2014a
Capture the value of arch
displayed by this
statement to use in the mex
command.
computer('arch')
ans = win64
To build the MEX file, copy the values of
matlabroot
and
arch
into the mex
command.
mex '-LC:\Program Files\MATLAB\R2014a\extern\lib\win64\microsoft' ... -llibmwlapack matrixDivide.c
You must use the '
characters because \Program
Files
in the path includes a space.
Define Compiler Directive
The mxcreatecharmatrixfromstr.c
example uses a #define
symbol SPACE_PADDING
to determine what character to use between character vectors in a matrix. To set the value, build the MEX file with the -D
option.
Copy the example to the current folder.
copyfile(fullfile(matlabroot,'extern','examples','mx','mxcreatecharmatrixfromstr.c'),'.','f')
Set the SPACE_PADDING
directive to add a space between values.
mex mxcreatecharmatrixfromstr.c -DSPACE_PADDING
Building with 'MinGW64 Compiler C '. MEX completed successfully.
Build Engine Application
Copy the engwindemo.c
engine example to the current
folder.
copyfile(fullfile(matlabroot,'extern','examples','eng_mat','engwindemo.c'),'.','f')
Build a standalone MATLAB engine application using the -client engine
syntax.
mex -client engine engwindemo.c
If you are running on a Windows platform, you must first register MATLAB as a COM server. For more information, see Register MATLAB as a COM Server.
Run the example.
!engwindemo
Select C Compiler
mex -setup
MATLAB displays the options for your version and system based on the list of Supported and Compatible Compilers.
Link Command Options
To add options to the mex
link command, use the
LINKFLAGS
command line option. For example, to
specify the environment for the executable when building
mymex.c
on Windows, type:
mex -v LINKFLAGS='$LINKFLAGS /subsystem:windows' mymex.c
Input Arguments
filenames
— One or more file names
string | character vector
One or more file names, including name and file extension, specified as a string or a character vector. If the file is not in the current folder, specify the full path to the file.
File names can be any combination of:
C, C++, or Fortran source files.
Simulink® S-function files.
Object files.
Static library files.
filenames
must include the fully qualified path to the library file. The library must be compiled with the same compiler currently used bymex
.To link dynamic libraries, use the
-l
option.libname
The first source code file listed in filenames
is the
name of the binary MEX file or engine application. To override this naming
convention, use the -output
option.
Use the MATLAB Editor to write your source code. If you use an integrated
development environment (IDE) such as Microsoft
Visual Studio or Xcode, then you can use the mex
command or
follow the guidelines in Custom Build with MEX Script Options.
MATLAB automatically selects a compiler, if installed, based on the
language of the filenames
arguments.
api
— Release-specific API
-R2017b
(default) | -R2018a
| -largeArrayDims
| -compatibleArrayDims
Links with the release-specific C Matrix API or Fortran Matrix API, specified as one of the values in the table. Do not combine these options.
Do not use this option for MEX files or engine applications using the MATLAB Data API for C++.
API | Description |
---|---|
| Builds with:
In a future version of
MATLAB, the default |
-R2018a | Builds with:
To run a Fortran MEX file built with the interleaved complex API in R2018a, you must use R2018a Update 3. |
-largeArrayDims | Builds with:
|
-compatibleArrayDims | Builds with:
Do not use the
Default option for C MEX S-functions only. |
Example: mex -R2018a explore.c
option1 ... optionN
— Optional build options
strings or character vectors corresponding to valid option flags
Optional build options, specified as one of the values in this table. Options can appear in any order on any platform, except where indicated.
Option | Description |
---|---|
| Uses a Windows RSP file. An RSP file is a text file containing command-line options. Non-ASCII characters are not supported. |
| Compiles an object file only. Does not build a binary MEX file. |
| Builds an engine application. |
| The
The Do not add
a space between D or U
and Example: Define Compiler Directive |
| Overrides
the default compiler selection.
Do
not use the |
| Adds symbolic information and disables optimization of built object code. Use for debugging. |
| Displays help for |
| Adds Do
not add a space between Example: Specify Path to Include File |
| Links with dynamic object library
MATLAB expands
If used, the Specify the To
link a static library, use the Example: Specify Path to Library File |
| Displays but does not execute commands that
Example: Preview Build Commands |
| Optimizes the object code. Use this option to compile with optimization. Optimization is enabled by default. Specify this option with the capital letter O. |
| Places all output files in folder
|
| Overrides the default MEX file naming mechanism.
Creates a binary MEX file named
Example: Combine Source Files Using Wild Card |
| Change the default compiler to build
|
| Suppresses informational messages. The
|
| Removes any initial definition of the C
preprocessor macro
Do not
add a space between |
| Builds in verbose mode. Displays values for internal variables after all command-line arguments are considered. Displays each compile and link step fully evaluated. Use for troubleshooting compiler setup problems. Example: Display Detailed Build and Troubleshooting Information |
| Append values to environment variable
Examples:
|
lang
— Language
C
(default) | C++
| CPP
| Fortran
Language, specified as one of these case-insensitive values.
C | C compilers, including C++ |
C++ or CPP | C++ compilers |
Fortran | Fortran compilers |
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 Windows
mexw64
Linux
mexa64
macOS with Apple silicon
mexmaca64
macOS with Intel®
mexmaci64
Note
MEX files built on macOS with Intel are not supported on the Apple silicon platform using Rosetta 2.
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.
Version History
Introduced before R2006aR2024b: Support for Intel oneAPI DPC++/C++ Compiler (icx)
MATLAB supports Intel oneAPI DPC++/C++ Compiler (icx) for C and C++ for building C and C++ interfaces, MEX files, and standalone MATLAB engine and MAT-file applications on Windows platforms.
R2024b: Support for Intel Fortran Compiler (ifx)
MATLAB supports the Intel Fortran Compiler (ifx) for building Fortran MEX files and standalone MATLAB engine and MAT-file applications on Windows platforms.
R2024a: Support for MinGW Compiler (Fortran)
MATLAB supports the MinGW Compiler (Fortran) for building Fortran MEX files and standalone MATLAB engine and MAT-file applications on Windows platforms. For installation instructions, see MATLAB Support for MinGW-w64 C/C++/Fortran Compiler.
R2023b: Support for Microsoft Visual Studio Build Tools
MATLAB supports Build Tools for Visual Studio 2022 and 2019 for C and C++ for building C and C++ interfaces, MEX files, and standalone MATLAB engine and MAT-file applications on Windows platforms.
R2023b: Support for NAG Fortran on Apple Silicon Platforms
MATLAB supports the NAG® Fortran compiler for building Fortran MEX files and standalone MATLAB engine and MAT-file applications on Apple silicon platforms.
R2023a: Support for MinGW-w64 version 8.1 compiler
MATLAB supports the MinGW-w64 version 8.1 compiler on Windows platforms. For installation instructions, see MATLAB Answers™ article FAQ: How do I install the MinGW compiler?
R2023a: Support for Intel oneAPI compilers
MATLAB supports these Intel oneAPI compilers:
oneAPI 2023 compiler with Microsoft Visual Studio 2019 and 2022.
oneAPI 2022 compiler with Visual Studio 2017, 2019, and 2022.
on Windows and macOS platforms for building:
C and C++ interfaces
C, C++, and Fortran MEX files
C, C++, and Fortran standalone MATLAB engine applications
C and Fortran standalone MATLAB MAT-file applications
R2023a: Removed -std=c++11
flag from MEX options files
MEX
options files for building C++ code with MinGW and Linux compilers no longer include the CXXFLAGS
flag
-std=c++11
.
MEX options files for macOS compilers include the CXXFLAGS
option
-std=c++14
instead.
To continue building MEX file myFunc
with the
-std=c++11
option, type:
mex myFunc.cpp 'CXXFLAGS=$CXXFLAGS -std=c++11'
R2022a: UTF-8 system encoding on Windows platforms
MATLAB now uses UTF-8 as its system encoding on Windows, completing the adoption of Unicode® across all supported platforms. System calls made from within a MEX file take and return UTF-8 encoded strings. If your MEX file contains code or links to third-party libraries that assume a different system encoding, then you might see garbled text and thus need to update the code to be Unicode compliant.
R2022a: MEX file macro FORTRAN_COMPLEX_FUNCTIONS_RETURN_VOID
has been removed
For MEX files built in R2021b and earlier, MATLAB provided a macro,
FORTRAN_COMPLEX_FUNCTIONS_RETURN_VOID
, to handle
platform-dependent calling syntax differences for passing complex numbers to Fortran
BLAS and LAPACK functions. As of R2022a, you no longer need a different calling
syntax on different platforms, and the macro for handling this difference has been
removed.
To update your code, replace statements such as these using
FORTRAN_COMPLEX_FUNCTIONS_RETURN_VOID
:
/* Call BLAS function */ /* Use a different call syntax on different platforms */ #ifdef FORTRAN_COMPLEX_FUNCTIONS_RETURN_VOID zdotu(&result, &nElements, zinA, &incx, zinB, &incy); #else result = zdotu(&nElements, zinA, &incx, zinB, &incy); #endif
with:
/* Call BLAS function */ zdotu(&result, &nElements, zinA, &incx, zinB, &incy);
R2021b: Support for Microsoft Visual Studio 2022 compiler
As of R2021b Update 3, MATLAB supports Microsoft Visual Studio 2022 for building C and C++ interfaces, MEX files, and standalone MATLAB engine and MAT-file applications.
R2020b: Support for gcc versions 5.x and higher on Linux platforms
MATLAB supports gcc versions 5.x and higher for building C and C++ interfaces, MEX files, and standalone MATLAB engine and MAT-file applications on Linux. If you use version 4.0 or earlier, then MATLAB displays a warning.
R2020a: UTF-8 system encoding on macOS and Linux platforms
On the macOS and Linux platforms, MATLAB uses UTF-8 as its system encoding. System calls made from within a MEX file built on macOS or Linux take and return UTF-8 encoded strings. If your MEX file contains code or links to third-party libraries that assume a different system encoding, then you might see garbled text and thus need to update the code to be Unicode compliant.
On the Windows platform, if the Use Unicode UTF-8 for worldwide language support option is enabled in the Windows Region settings, then MATLAB uses UTF-8 as its system encoding.
R2020a: Compiler support changed
This table lists the changes to compiler support in MATLAB for building C and C++ interfaces, MEX files, and standalone MATLAB engine and MAT-file applications.
For continued support for building your applications, consider upgrading to a supported compiler shown in Supported and Compatible Compilers – Release 2020a.
Support | Compiler | Platform |
---|---|---|
Added | Intel Parallel Studio XE 2020 for C, C++, and Fortran | Windows |
Added | Intel Parallel Studio XE 2020 for Fortran | macOS |
Added | Apple Xcode 11.x | macOS |
Discontinued | Intel Parallel Studio XE 2017 | Windows macOS |
R2019b: Compiler support changed
This table lists the changes to compiler support in MATLAB for building C and C++ interfaces, MEX files, and standalone MATLAB engine and MAT-file applications.
For continued support for building your applications, consider upgrading to a supported compiler shown in Supported and Compatible Compilers – Release 2019b.
Support | Compiler | Platform |
---|---|---|
Added | Microsoft Visual Studio 2019 for C and C++ | Windows |
Discontinued | Intel Parallel Studio XE 2015 and XE 2016 for Fortran | Windows macOS |
R2019b: C MEX and engine applications: true
, false
, and bool
defined by <stdbool.h>
The definitions for true
, false
, and
bool
have changed for building MEX files and standalone
MATLAB engine and MAT-file applications with C99 compatible compilers on
Windows and Linux platforms. MATLAB defines these values using <stdbool.h>
as
defined by IEEE Std 1003.1:
The <stdbool.h> header shall define the following macros: bool Expands to _Bool. true Expands to the integer constant 1. false Expands to the integer constant 0. _bool_true_false_are_defined Expands to the integer constant 1.
In R2019a and earlier, MATLAB defined these values on Windows and Linux platforms as:
true
—#defined
as1
false
—#defined
as0
bool
—typedef
asunsigned char
For macOS platforms, there is no change.
R2019a: Support for Intel Parallel Studio XE 2019 compilers
This table lists the added Intel compiler support in MATLAB for building C and C++ interfaces, MEX files, and standalone MATLAB engine and MAT-file applications.
Support | Compiler | Platform |
---|---|---|
Added | Intel Parallel Studio XE 2019 with Microsoft Visual Studio 2015 and 2017 for C, C++, and Fortran | Windows |
Added | Intel Parallel Studio XE 2019 for Fortran | macOS |
R2018b: Build Fortran MEX files with interleaved complex API
The Fortran Matrix API supports the interleaved storage representation of complex numbers. For more information, see MATLAB Support for Interleaved Complex API in MEX Functions
If you build Fortran MEX functions, then you should review Do I Need to Upgrade My MEX Files to Use Interleaved Complex API?
Note
To run a Fortran MEX file built with the interleaved complex API in R2018a, you must use R2018a Update 3.
R2018b: Compiler support changed
This table lists the changes to compiler support in MATLAB for building C interfaces, MEX files, and standalone MATLAB engine and MAT-file applications.
For continued support for building your applications, consider upgrading to a supported compiler shown in Supported and Compatible Compilers – Release 2018b.
Support | Compiler | Platform |
---|---|---|
Added | MinGW-w64 version 6.3.0 compiler from https://www.mingw-w64.org/ | Windows |
Added | Intel Parallel Studio XE 2018 with Microsoft Visual Studio 2015 and 2017 for C, C++, and Fortran | Windows |
Added | Intel Parallel Studio XE 2018 for Fortran | macOS |
Discontinued | Microsoft Visual C++® 2013 Professional | Windows |
R2018a: Access MATLAB data and objects more easily from C++
Author MEX functions using modern C++ design patterns, extended data type support, and MATLAB copy-on-write semantics for faster handling of large data arrays. For more information, see Write C++ Functions Callable from MATLAB (MEX Files).
If you do not need MEX files that work in R2017b and earlier and you are familiar with modern C++, then consider using the new C++ MEX API and MATLAB Data API for C++. If you are more comfortable working in the C language, continue using the C MEX API and the C Matrix API.
R2018a: Build C MEX files with interleaved complex API
MATLAB uses an interleaved storage representation of complex numbers. The term interleaved complex refers to this representation, where the real and imaginary parts are stored together. For more information, see MATLAB Support for Interleaved Complex API in MEX Functions.
If you build C MEX functions, C/C++ MEX S-functions, or standalone MATLAB engine and MAT-file applications, then you should review Do I Need to Upgrade My MEX Files to Use Interleaved Complex API? MATLAB does not support the interleaved complex API for Fortran functions.
This change does not affect the MATLAB language. You can continue to use the functionality described in Complex Numbers without any modification of your functions and scripts.
R2018a: Release-specific build options
The mex
command has new build options,
-R2017b
and -R2018a
, which link with
release-specific versions of the C Matrix API.
-R2017b
— Default option. This option is equivalent to the command:mex mymex.c -largeArrayDims -DMEX_DOUBLE_HANDLE
-R2018a
— Uses the interleaved complex API, which includes the typed data access functions. For more information, see MATLAB Support for Interleaved Complex API in MEX Functions.
R2018a: Specify version of Boost library
Although MATLAB builds with Boost library version 1.56.0, as of R2018a, you can specify any Boost library version in a MEX function.
R2018a: Compiler support changed
This table lists the changes to compiler support in MATLAB for building C interfaces, MEX files, and standalone MATLAB engine and MAT-file applications.
For continued support for building your applications, consider upgrading to a supported compiler shown in Supported and Compatible Compilers – Release 2018a.
Support | Compiler | Platform |
---|---|---|
Added | GNU® gcc and gfortran version 6.x. Version 6.3 recommended. | Linux |
Discontinued | GNU gcc and gfortran version 4.9.x | Linux |
Discontinued | Apple Xcode 7.x | macOS |
Discontinued | Intel C++ Composer XE 2013 | Windows |
Discontinued | Intel Visual Fortran Composer XE 2013 | Windows |
Discontinued | Intel Fortran Composer XE 2013 | macOS |
To be phased out | Visual C++ 2013 Professional | Windows |
R2017b: Compiler support changed
This table lists the changes to compiler support in MATLAB for building C interfaces, MEX files, and standalone MATLAB engine and MAT-file applications.
For continued support for building your applications, consider upgrading to a supported compiler shown in Supported and Compatible Compilers – Release 2017b.
Support | Compiler | Platform |
---|---|---|
Added | Microsoft Visual C++ 2017 Professional, Community, and Enterprise editions | Windows |
Added | Microsoft Visual C++ 2015 and 2013 Community and Enterprise editions in addition to continued support for the Professional edition | Windows |
Added | Microsoft Visual Studio 2015 (v140) toolset installed over Visual Studio 2017 | Windows |
Added | MinGW-w64 version 5.3.0 compiler from https://www.mingw-w64.org/ | Windows |
Added | Intel Parallel Studio XE 2017 with Microsoft Visual Studio 2017 for C, C++, and Fortran | Windows |
Discontinued | MinGW-w64 version 4.9.2 compiler from TDM-GCC | Windows |
Discontinued | Microsoft Visual C++ 2012 Professional | Windows |
Discontinued | Microsoft Windows SDK 7.1 | Windows |
To be phased out | Support for GNU gcc and gfortran version 4.9 will be discontinued in a future release, at which time new versions will be supported. | Linux |
R2017a: MEX builds with 64-bit API by default
The mex
function uses the large-array-handling API
(-largeArrayDims
option) by default. Best practice is to
update your MEX source code to use this library and rebuild the MEX file. For
instructions, see Upgrade MEX Files to Use Interleaved Complex API.
You can run existing binary MEX files without rebuilding. For more information, see MEX Version Compatibility.
If you build MEX files without using the mex
command options
-largeArrayDims
or -compatibleArrayDims
,
then review the following table to avoid depending on default behavior that changes
in R2017a. For information about the consequences of using the
-compatibleArrayDims
option to build MEX files, see What If I Do Not Upgrade?
The default build mode for C MEX S-functions remains
-compatibleArrayDims
.
This table shows the changes you must make to your mex
command to rebuild MEX files or S-functions.
Source Code | mex command — R2016b and earlier | mex command — R2017a and later |
---|---|---|
MEX file C/C++ or Fortran source code uses 32-bit API | mex myMex.c | mex myMex.c -compatibleArrayDims |
mex myMex.c -compatibleArrayDims | No change. | |
MEX file C/C++ or Fortran source code uses 64-bit API | mex myMex.c -largeArrayDims | Use: Or continue to
use: |
S-function C/C++ source code uses 32-bit API | mex sfun.c | No change. |
mex sfun.c -compatibleArrayDims | No change. | |
S-function C/C++ source code uses 64-bit API | mex sfun.c -largeArrayDims | No change. |
S-function Fortran source code uses 32-bit API | mex sfun.F | mex sfun.F -compatibleArrayDims |
S-function Fortran source code uses 64-bit API | mex sfun.F -largeArrayDims | No change. |
R2017a: Compiler support changed
MATLAB added support for the compilers in this table for building C interfaces, MEX files, and standalone MATLAB engine and MAT-file applications.
Support | Compiler | Platform |
---|---|---|
Added | Intel Parallel Studio XE 2017 | Windows |
Added | Intel Parallel Studio XE 2017 for Fortran | macOS |
Added | Xcode 8.x, as of R2016b | macOS |
R2016b: Version embedded in MEX files
The mex
command embeds a MEX version number in MEX files
built by MATLAB R2016b and later. This number identifies the version of the Matrix API
that the MEX function expects to link against at runtime.
If you do not use the mex
command, then you must update the
commands you use to build MEX files. For more information, see Compiling MEX Files without the mex Command.
R2016b: Compiler support changed
This table lists the changes to compiler support in MATLAB for building C interfaces, MEX files, and standalone MATLAB engine and MAT-file applications.
For continued support for building your applications, consider upgrading to a supported compiler shown in Supported and Compatible Compilers – Release 2016b.
Support | Compiler | Platform |
---|---|---|
Added | GNU gcc and gfortran version 4.9 | Linux |
Discontinued | GNU gcc and gfortran version 4.7 | Linux |
Added | Intel Parallel Studio XE 2016 for Fortran
| Mac OS X |
Discontinued | Microsoft Visual Studio 2010 Professional | Windows |
To be phased out | Visual C++ 2012 Professional Apple Xcode 6.2 | Windows Mac OS X |
R2016a: MEX command does not accept .bat
or .sh
compiler options files
The mex
command -f
option does not accept
arguments with .bat
or .sh
file
extensions.
Instead of using the -f
option to specify a compiler, use the
workflows described in Change Default Compiler.
You can modify compiler build options using mex
command
options. For example, use the -L
and -I
options to locate libraries on your system. Use the
option to pass options to the compiler.varname
=varvalue
R2016a: Compiler support changed
This table lists the changes to compiler support in MATLAB for building C interfaces, MEX files, and standalone MATLAB engine and MAT-file applications.
For continued support for building your applications, consider upgrading to a supported compiler shown in Supported and Compatible Compilers – Release 2016a.
Support | Compiler | Platform |
---|---|---|
Added | Intel Parallel Studio XE 2016
| Windows |
Added | Apple Xcode 7.x | Mac OS X |
Discontinued | Microsoft
Visual Studio 2008 Professional Edition
| Windows |
To be phased out | Microsoft
Visual Studio 2010 Professional
Edition | Windows |
See Also
dbmex
| mexext
| computer
| system
Topics
- Tables of MEX Function Source Code Examples
- Supported and Compatible Compilers
- Change Default Compiler
- MATLAB Data API for C++
- Build C++ MEX Programs
- C Matrix API
- Fortran Matrix API
- Build C MEX Function
- Upgrade MEX Files to Use Interleaved Complex API
- Upgrade MEX Files to Use 64-Bit API
- Upgrade MEX Files to Use Graphics Objects
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)