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

4.237 views (last 30 days)

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 21 Mar 2023
Edited: MathWorks Support Team on 21 Mar 2023
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.
Be aware that in order for any changes to be permanent, the "MATLAB Support for MinGW-w64 C/C++ Compiler" support package must be uninstalled if it was previously installed.
For MATLAB R2017b and later:
Verify that you have installed MinGW-w64 version 5.3 (or MinGW-w64 version 6.3 for R2018b and later, or MinGW-w64 version 8.1 for R2023a) 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 and seeing what the MW_MINGW64_LOC environment variable detected by MATLAB is set to:
>> mex -setup -v
Note: Be aware that due to caching limitations, the option to select the "MinGW64 Compiler" after running this command may show the incorrect command to be run. In reality, clicking on this option will use the version of MinGW pointed to by the MW_MINGW64_LOC environment variable.

Sign in to comment.

More Answers (0)




Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by