Asked by MathWorks Support Team
on 21 Nov 2016

I already have MinGW on my computer. How do I configure it to work with MATLAB?

Answer by MathWorks Support Team
on 18 May 2018

Edited by MathWorks Support Team
on 18 May 2018

Accepted Answer

MATLAB detects the MinGW compiler by reading the environment variable MW_MINGW64_LOC. When you install MinGW from the MATLAB Add-Ons menu, MATLAB sets this variable. The following instructions can be used to set this environment variable manually.

For MATLAB R2017b and later:

Verify you have installed MinGW-w64 version 5.3 before following these steps.

1) Download the attached MATLAB function 'configuremingw'.

2) Identify the full path to the MinGW installation directory containing the MinGW compiler binaries. This is identified as MINGWROOT.

3) In the MATLAB Command Window run:

>> configuremingw(MINGWROOT)

Alternatively, run:

>> configuremingw

Then navigate to MINGWROOT.

For MATLAB R2015b through R2017a:

Verify you have installed MinGW-w64 version 4.9.2 before following these steps.

The MW_MINGW64_LOC environment variable can be (A) set for the entire system level or (B) set temporarily every time you open MATLAB. Administrative privileges are required to set MW_MINGW64_LOC as a system environment variable. No special privileges are required to set the environment variable temporarily.

(A) To set MW_MINGW64 as a system environment variable on Windows 7/8/10:

- Make sure you have administrative privileges.
- Select Computer from the Start menu.
- Choose System properties from the context menu.
- Click Advanced system settings > Advanced tab.
- Click Environment Variables.
- Under System variables, select New.
- In the New System Variable dialog box, type MW_MINGW64_LOC in the Variable name field.
- In the Variable value field, type the location of the MinGW-w64 compiler installation, for example, 'C:\TDM-GCC-64'.
- Click "OK" to close the dialog boxes, then close the Control Panel dialog box.

(B) To set MW_MINGW64 as a temporary environment variable using MATLAB:

Run the following in the MATLAB Command Window:

>> setenv('MW_MINGW64_LOC',folder)

where 'folder' is the installation directory of MinGW. For example, 'C:\TDM-GCC-64'. This command will need to be run every time you start MATLAB for MATLAB to correctly use MinGW. You can consider adding the above command to your 'startup.m' file. This will execute the command every time MATLAB starts up.

To Verify:

After performing the above steps, you can verify if the compiler was recognized by MATLAB by running the following command:

>> mex -setup

Answer by S Crombie
on 22 Nov 2017

I am using MATLAB 2017b so followed the first set of instructions. After setting MINGWROOT = 'C:\mingw64' and running configuremingw(MINGWROOT) I get the following error: Undefined variable "mex_spkg" or class "mex_spkg.getEnvVarName".

Error in configuremingw

Where are these variables supposed to be? Have I not configured the path correctly? Grateful for any advice.

ALTAF KHAN
on 15 Feb 2018

I have same issue did you find how can we resolve it?

Deepa
on 5 Oct 2018

Walter Roberson
on 5 Oct 2018

setenv('MW_MINGW64_LOC', 'c:\program files(x86)\mingw-w64')

If it works there will be no output from MATLAB, but you could check afterwards with

getenv('MW_MINGW64_LOC')

Sign in to comment.

Answer by racharla
on 28 Feb 2018

ALTAF KHAN
on 28 Feb 2018

varjak
on 16 Jun 2018

Sign in to comment.

Answer by emrah sever
on 4 Dec 2017

Thank you. The explanation solved my problem

Sign in to comment.

Answer by Wesley P
on 31 Jan 2018

Hi Crombie, can you share the link for the installer to install manually. Thank you

S Crombie
on 15 Feb 2018

I think this is the place I found it. The MATLAB instructions say use version 5.3.

Wesley P
on 20 Feb 2018

Sign in to comment.

Answer by Fabrice
on 25 Jun 2018

Edited by Fabrice
on 25 Jun 2018

I have VisualStudio 2017 too, but mex -setup cannot find/use the included compilers ? What are the solutions to have Matlab mex files working in this configuration ?

SW

- Matlab 2014a
- Windows 10 x64
- Various compilers installed (VS2017, MinGW...) ; could install another one if needed

HW

- Intel Core i7

Walter Roberson
on 25 Jun 2018

Sign in to comment.

Answer by Afaf Saad
on 23 Sep 2018

Edited by Afaf Saad
on 23 Sep 2018

i downloaded version 8 and installed but i can not connect it with matlab, any help?

am getting this error: ">> configuremingw Error using configuremingw Folder 'C:\Program Files (x86)\mingw-w64' does not contain MinGW binaries."

Oliver Burke
on 6 Nov 2018

Anastasia
on 30 Jan 2019

Try to set as configuration folder the folder which has binary. For me it was "C:\mingw-w64\mingw32". It seems this path is not always the same for different installations. To check, where matlab is looking for binaries use "mex -setup -v". And you will get the info:

... Looking for compiler 'MinGW64 Compiler (C)' ...

... Looking for environment variable 'MW_MINGW64_LOC' ...Yes ('C:\mingw-w64').

... Looking for file 'C:\mingw-w64\bin\gcc.exe' ...No.

The third one was wrong for me. There is no bin-folder in "C:\mingw-w64". This folder was in "C:\mingw-w64\mingw32". When I have changed it, everything was OK. Hope, it will help you. Good luck!

Ed Mendes
on 10 Mar 2019

Hello

I have followed the steps shown above and got mex -setup to see the mingw binaries. However when I try mex yprime.c, an error comes up.

Building with 'MinGW64 Compiler (C)'.

C:\mingw-w64\i686-6.3.0-posix-dwarf-rt_v5-rev2\mingw32\bin\gcc -c -DUSE_MEX_CMD -m64 -DMATLAB_MEX_FILE -I"C:\Program Files\MATLAB\R2017b/extern/include" -I"C:\Program Files\MATLAB\R2017b/simulink/include" -I"C:\Program Files\MATLAB\R2017b/extern\lib\win64\mingw64" -fexceptions -fno-omit-frame-pointer -O2 -fwrapv -DNDEBUG "C:\Users\virtual_000\Documents\MATLAB\yprime.c" -o C:\Users\virtual_~1\AppData\Local\Temp\mex_1847762154678_3576\yprime.obj

Error using mex

C:\Users\virtual_000\Documents\MATLAB\yprime.c:1:0: sorry, unimplemented: 64-bit mode not

compiled in

/*=================================================================

Mingw-64 came as result of using mingw-w64-install from where I choose the version to be installed (\i686-6.3.0-posix-dwarf-rt_v5-rev2).

What could be wrong?

Many thanks

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 20 Comments

## bassem abdelwahed (view profile)

Direct link to this comment:https://se.mathworks.com/matlabcentral/answers/313298-i-already-have-mingw-on-my-computer-how-do-i-configure-it-to-work-with-matlab#comment_415704

## Kyle Perry (view profile)

Direct link to this comment:https://se.mathworks.com/matlabcentral/answers/313298-i-already-have-mingw-on-my-computer-how-do-i-configure-it-to-work-with-matlab#comment_416787

## Ji Tan (view profile)

Direct link to this comment:https://se.mathworks.com/matlabcentral/answers/313298-i-already-have-mingw-on-my-computer-how-do-i-configure-it-to-work-with-matlab#comment_471829

## Munawwar Sohul (view profile)

Direct link to this comment:https://se.mathworks.com/matlabcentral/answers/313298-i-already-have-mingw-on-my-computer-how-do-i-configure-it-to-work-with-matlab#comment_487505

## Ling Smile (view profile)

Direct link to this comment:https://se.mathworks.com/matlabcentral/answers/313298-i-already-have-mingw-on-my-computer-how-do-i-configure-it-to-work-with-matlab#comment_488643

## qilin guo (view profile)

Direct link to this comment:https://se.mathworks.com/matlabcentral/answers/313298-i-already-have-mingw-on-my-computer-how-do-i-configure-it-to-work-with-matlab#comment_518759

## Mark Thomas (view profile)

Direct link to this comment:https://se.mathworks.com/matlabcentral/answers/313298-i-already-have-mingw-on-my-computer-how-do-i-configure-it-to-work-with-matlab#comment_525114

## Tobias Schillinger (view profile)

Direct link to this comment:https://se.mathworks.com/matlabcentral/answers/313298-i-already-have-mingw-on-my-computer-how-do-i-configure-it-to-work-with-matlab#comment_530886

## Mark Thomas (view profile)

Direct link to this comment:https://se.mathworks.com/matlabcentral/answers/313298-i-already-have-mingw-on-my-computer-how-do-i-configure-it-to-work-with-matlab#comment_532032

## Priyesh Rabadiya (view profile)

Direct link to this comment:https://se.mathworks.com/matlabcentral/answers/313298-i-already-have-mingw-on-my-computer-how-do-i-configure-it-to-work-with-matlab#comment_613544

## Walter Roberson (view profile)

Direct link to this comment:https://se.mathworks.com/matlabcentral/answers/313298-i-already-have-mingw-on-my-computer-how-do-i-configure-it-to-work-with-matlab#comment_613553

## takoua mekni (view profile)

Direct link to this comment:https://se.mathworks.com/matlabcentral/answers/313298-i-already-have-mingw-on-my-computer-how-do-i-configure-it-to-work-with-matlab#comment_637472

## Sanket (view profile)

Direct link to this comment:https://se.mathworks.com/matlabcentral/answers/313298-i-already-have-mingw-on-my-computer-how-do-i-configure-it-to-work-with-matlab#comment_688861

## Walter Roberson (view profile)

Direct link to this comment:https://se.mathworks.com/matlabcentral/answers/313298-i-already-have-mingw-on-my-computer-how-do-i-configure-it-to-work-with-matlab#comment_688882

## Sanket (view profile)

Direct link to this comment:https://se.mathworks.com/matlabcentral/answers/313298-i-already-have-mingw-on-my-computer-how-do-i-configure-it-to-work-with-matlab#comment_688896

## Sanket (view profile)

Direct link to this comment:https://se.mathworks.com/matlabcentral/answers/313298-i-already-have-mingw-on-my-computer-how-do-i-configure-it-to-work-with-matlab#comment_688897

## Walter Roberson (view profile)

Direct link to this comment:https://se.mathworks.com/matlabcentral/answers/313298-i-already-have-mingw-on-my-computer-how-do-i-configure-it-to-work-with-matlab#comment_688903

## Sanket (view profile)

Direct link to this comment:https://se.mathworks.com/matlabcentral/answers/313298-i-already-have-mingw-on-my-computer-how-do-i-configure-it-to-work-with-matlab#comment_688968

## Tarun Cousik (view profile)

Direct link to this comment:https://se.mathworks.com/matlabcentral/answers/313298-i-already-have-mingw-on-my-computer-how-do-i-configure-it-to-work-with-matlab#comment_703959

## Walter Roberson (view profile)

Direct link to this comment:https://se.mathworks.com/matlabcentral/answers/313298-i-already-have-mingw-on-my-computer-how-do-i-configure-it-to-work-with-matlab#comment_703978

Sign in to comment.