MATLAB Answers

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

1,674 views (last 30 days)
I already have MinGW on my computer. How do I configure it to work with MATLAB?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 18 May 2018
Edited: MathWorks Support Team on 18 May 2018
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:
  1. Make sure you have administrative privileges.
  2. Select Computer from the Start menu.
  3. Choose System properties from the context menu.
  4. Click Advanced system settings > Advanced tab.
  5. Click Environment Variables.
  6. Under System variables, select New.
  7. In the New System Variable dialog box, type MW_MINGW64_LOC in the Variable name field.
  8. In the Variable value field, type the location of the MinGW-w64 compiler installation, for example, 'C:\TDM-GCC-64'.
  9. 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

  21 Comments

Tarun Cousik
Tarun Cousik on 10 May 2019
The attachment opens a new link with some garbage code/symbols in it- is it supposed to be this way?
Walter Roberson
Walter Roberson on 10 May 2019
Yes, the attachment is a .p file, which is a binary file of encoded MATLAB source. You can Save As (or equivalent for your browser) to download it, and then move it to the proper location.
Richard Crozier
Richard Crozier on 20 Jan 2020
I am trying the described solution in Matlab R2018a. If I run without administrator priviliges I get the following when trying to run configuremingw
>> configuremingw
Error using configuremingw
Unable to setup the MinGW compiler due to administrator privileges not granted
I then tried manually changing MW_MINGW64_LOC but without success, see the below matlab session:
>> mex -setup C++
MEX configured to use 'MinGW64 Compiler (C++)' for C++ language compilation.
Warning: The MATLAB C and Fortran API has changed to support MATLAB
variables with more than 2^32-1 elements. You will be required
to update your code to utilize the new API.
You can find more information about this at:
https://www.mathworks.com/help/matlab/matlab_external/upgrading-mex-files-to-use-64-bit-api.html.
>> getenv ('MW_MINGW64_LOC')
ans =
'C:\ProgramData\MATLAB\SupportPackages\R2018a\3P.instrset\mingw_w64.instrset'
>> mingwdir = getenv ('MW_MINGW64_LOC')
mingwdir =
'C:\ProgramData\MATLAB\SupportPackages\R2018a\3P.instrset\mingw_w64.instrset'
>> ls (mingwdir)
. build-info.txt lib opt
.. etc libexec share
bin include licenses x86_64-w64-mingw32
>> ls ('C:\Program Files\mingw-w64\x86_64-6.3.0-posix-seh-rt_v5-rev2\mingw64')
. build-info.txt lib opt
.. etc libexec share
bin include licenses x86_64-w64-mingw32
>> setenv ('MW_MINGW64_LOC', 'C:\Program Files\mingw-w64\x86_64-6.3.0-posix-seh-rt_v5-rev2\mingw64')
>> getenv ('MW_MINGW64_LOC')
ans =
'C:\Program Files\mingw-w64\x86_64-6.3.0-posix-seh-rt_v5-rev2\mingw64'
>> mex -setup
MEX configured to use 'MinGW64 Compiler (C)' for C language compilation.
Warning: The MATLAB C and Fortran API has changed to support MATLAB
variables with more than 2^32-1 elements. You will be required
to update your code to utilize the new API.
You can find more information about this at:
https://www.mathworks.com/help/matlab/matlab_external/upgrading-mex-files-to-use-64-bit-api.html.
To choose a different language, select one from the following:
mex -setup C++
mex -setup FORTRAN
>> mex -setup C++
Error using mex
No supported compiler was found. You can install the freely available MinGW-w64 C/C++ compiler; see Install MinGW-w64 Compiler.
For more options, visit https://www.mathworks.com/support/compilers.
>> mex -setup FORTRAN
Error using mex
No supported compiler was found. For options, visit https://www.mathworks.com/support/compilers.
>> CC = mex.getCompilerConfigurations
CC =
2×1 CompilerConfiguration array with properties:
Name
Manufacturer
Language
Version
Location
ShortName
Priority
Details
LinkerName
LinkerVersion
MexOpt
>> CC(1)
ans =
CompilerConfiguration with properties:
Name: 'MinGW64 Compiler (C++)'
Manufacturer: 'GNU'
Language: 'C++'
Version: '5.3.0'
Location: 'C:\Program Files\mingw-w64\x86_64-6.3.0-posix-seh-rt_v5-rev2\mingw64'
ShortName: 'mingw64-g++'
Priority: 'E'
Details: [1×1 mex.CompilerConfigurationDetails]
LinkerName: 'C:\Program Files\mingw-w64\x86_64-6.3.0-posix-seh-rt_v5-rev2\mingw64\bin\g++'
LinkerVersion: ''
MexOpt: 'C:\Users\User\AppData\Roaming\MathWorks\MATLAB\R2018a\mex_C++_win64.xml'
>> CC(2)
ans =
CompilerConfiguration with properties:
Name: 'MinGW64 Compiler (C)'
Manufacturer: 'GNU'
Language: 'C'
Version: '5.3.0'
Location: 'C:\Program Files\mingw-w64\x86_64-6.3.0-posix-seh-rt_v5-rev2\mingw64'
ShortName: 'mingw64'
Priority: 'E'
Details: [1×1 mex.CompilerConfigurationDetails]
LinkerName: 'C:\Program Files\mingw-w64\x86_64-6.3.0-posix-seh-rt_v5-rev2\mingw64\bin\gcc'
LinkerVersion: ''
MexOpt: 'C:\Users\User\AppData\Roaming\MathWorks\MATLAB\R2018a\mex_C_win64.xml'
>> rnfoundry_setup
Setting up mexslmeval.
Warning: mexslmeval compilation failed, you may be missing required libraries, gsl and gslcblas
> In mexslmeval_setup (line 63)
In rnfoundry_setup (line 319)
Finished building mexslmeval.
Setting up mexMBCNodal and mexMBCNodalSharedMem.
Warning: Unable to compile mex function mexMBCNodal. Error reported was:
No supported compiler was found. You can install the freely available MinGW-w64 C/C++ compiler; see Install MinGW-w64 Compiler.
For more options, visit https://www.mathworks.com/support/compilers.
As you can see, merely changing the MW_MINGW64_LOC does not corectly modify the compiler configurations, at least when matlab is run as non-root.
I tried again, after starting matlab.exe using 'Run as administrator' as below:
If I do this, I get the exact same issue when tryiong to run configuremingw
>> configuremingw ('C:\Program Files\mingw-w64\x86_64-6.3.0-posix-seh-rt_v5-rev2\mingw64')
Error using configuremingw
Unable to setup the MinGW compiler due to administrator privileges not granted.
setenv doesn't help either
>> setenv ('MW_MINGW64_LOC', 'C:\Program Files\mingw-w64\x86_64-6.3.0-posix-seh-rt_v5-rev2\mingw64')
>> mex -setup
MEX configured to use 'MinGW64 Compiler (C)' for C language compilation.
Warning: The MATLAB C and Fortran API has changed to support MATLAB
variables with more than 2^32-1 elements. You will be required
to update your code to utilize the new API.
You can find more information about this at:
https://www.mathworks.com/help/matlab/matlab_external/upgrading-mex-files-to-use-64-bit-api.html.
To choose a different language, select one from the following:
mex -setup C++
mex -setup FORTRAN
>> mex -setup C++
Error using mex
No supported compiler was found. You can install the freely available MinGW-w64 C/C++ compiler; see Install MinGW-w64 Compiler. For
more options, visit https://www.mathworks.com/support/compilers.
As others have noted, if configuremingw wasn't an obfuscated p file I could attempt to fix this. My suspicion is that configuremingw calls another system program or script which doesn't run with the same permissions.
Any suggestions for getting an alternative mingw to work on R2018a?
p.s. I also tried activating the administrator account, logging in as administrator and still get
>> configuremingw
Error using configuremingw
Unable to setup the MinGW compiler due to administrator privileges not granted.

Sign in to comment.

More Answers (9)

S Crombie
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.

  4 Comments

Show 1 older comment
Deepa
Deepa on 5 Oct 2018
i have similar issue I am using R2018b, where after installing minwg-64 with pc, I tried opening via command prompt. I changed environmental variable also, still I am not getting any response if I type "setenv('MW_MINGW64_LOC',c:\program files(x86)\mingw-w64)".. no response in matlab... how shall I overcome this ?
Walter Roberson
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.


racharla
racharla on 28 Feb 2018
I did as per above said..I use matlab2017a I have configured environmental variables and I am having MinGw in some location in my system and I have given location in environment variables but even then I am getting same error like "Error using mex No supported compiler or SDK was found. You can install the freely available MinGW-w64 C/C++ compiler; see Install MinGW-w64 Compiler. For more options, visit http://www.mathworks.com/support/compilers/R2017a/." Can anyone please me

  2 Comments

ALTAF KHAN
ALTAF KHAN on 28 Feb 2018
hello , you can find instruction available MinGw-w64 C/C++ compiler, Thing what i understand when do you finish the installation shut down the Matlab and then restart again. Note that you already set the environment variable.
varjak
varjak on 16 Jun 2018
I had the same probem but then I realized that I had set the wrong path to the environment variable. I now have it as "C:\MinGW\mingw64" and it works. Make sure the path does NOT have any spaces, like "C:\Program Files\MinGW\mingw64" to avoid future erros, and that the bit version corresponds to your machine's!

Sign in to comment.



Wesley P
Wesley P on 31 Jan 2018
Hi Crombie, can you share the link for the installer to install manually. Thank you

  2 Comments

Wesley P
Wesley P on 20 Feb 2018
Hi Crombie Thanks for sharing the link , I tried but I land on the message when I click Next - "Cannot download repository.txt" and exits, can you help me on this issue. I have Windows 10 OS.

Sign in to comment.



Fabrice
Fabrice on 25 Jun 2018
Edited: 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

  1 Comment

Walter Roberson
Walter Roberson on 25 Jun 2018
See https://www.mathworks.com/content/dam/mathworks/mathworks-dot-com/support/sysreq/files/SystemRequirements-Release2014a_SupportedCompilers.pdf for the list of compilers you can use. Note that where it talks about Professional editions, it really does mean Professional editions (or Ultimate editions), not Community or Express editions.

Sign in to comment.


Afaf Saad
Afaf Saad on 23 Sep 2018
Edited: 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."

  5 Comments

Show 2 older comments
Oliver Burke
Oliver Burke on 6 Nov 2018
Similarly, I have r2018b, downloaded mingw-64 and run configuremingw, but get: ">> configuremingw Error using configuremingw Folder 'C:\mingw-w64' does not contain MinGW binaries." I can't find anything to show how minGW works with r2018b.
Anastasia
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!
Wingw64_Path.png
Ed Mendes
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.


zeng xianren
zeng xianren on 30 May 2019
I have matlabR2008a. To run 'mbuild -setup', the matlab can't connect the gcc, can you help me ?

  3 Comments

Sign in to comment.


Jawhar Chebbi
Jawhar Chebbi on 5 Sep 2019
Edited: Jawhar Chebbi on 5 Sep 2019
Hello, this is not working for me. I have Matlab 2017b, I run it as administrator and when I execute the function configuremingw with the correct path, I get the following error
Error using configuremingw
Unable to setup the MinGW compiler due to administrator privileges not granted.

Products


Release

R2016b