This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

MinGW-w64 Compiler

You can use the MinGW-w64 compiler to build MEX files and standalone MATLAB® engine and MAT-file applications. To install the compiler, use the Add-Ons menu described in Get Add-Ons. Search for MinGW or select from Features. For more information, see

Building yprime.c Example

You can test the MinGW® compiler by building the yprime.c example. Copy the source file to a writable folder.


If you only have the MinGW compiler installed on your system, the mex command automatically chooses MinGW. Go to the next step. However, if you have multiple C or C++ compilers, use mex -setup to choose MinGW.

mex -setup

Build the MEX file.

mex yprime.c

MATLAB displays a “Building with” message showing what compiler was used to build the MEX file.

Run the function.


For more information, see Troubleshooting and Limitations Compiling C/C++ MEX Files with MinGW-w64.

MinGW Installation Folder Cannot Contain Space

Do not install MinGW in a location with spaces in the path name. For example, do not use:

C:\Program Files\mingw-64

Instead, use:


Updating MEX Files to Use MinGW Compiler

If you have MEX source files built with a different MATLAB-supported compiler, you might need to modify the code in order to build with the MinGW compiler. For example:

  • Library (.lib) files generated by Microsoft® Visual Studio® are not compatible with MinGW.

  • Object cleanup is not possible when an exception is thrown using the mexErrMsgIdAndTxt function from C++ MEX files, resulting in memory leak.

  • An uncaught exception in C++ MEX files compiled with MinGW causes MATLAB to crash.

  • MEX files with variables containing large amounts of data cannot be compiled, as the compiler runs out of memory.

Related Topics

External Websites

Was this topic helpful?