MATLAB Answers

1

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

Asked by MathWorks Support Team on 21 Nov 2016
Latest activity Commented on by Mark Thomas on 16 Jan 2018 at 12:10

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

3 Answers

Answer by MathWorks Support Team on 21 Sep 2017
Edited by MathWorks Support Team on 21 Sep 2017
 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:

  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

  7 Comments

Hi Bassem, follow your steps, I still got the same problem? Could you help me? Thanks! If possible, send me a email smilelingyong@hust.edu.cn. Thanks a lot!

>>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: http://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 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: http://www.mathworks.com/help/matlab/matlab_external/upgrading-mex-files-to-use-64-bit-api.html.

Hello, My MATLAB R2017b Version encountered an error when I run configuremingw.p in the MATLAB Command Window, it says:

>> configuremingw

未定义变量 "mex_spkg" 或类 "mex_spkg.getEnvVarName"。

出错 configuremingw

By the way,the path of MinGW is C:\MinGW.

Also running R2017b.

I ran MATLAB R2017b with admin rights, ran configuremingw (navigating to the installation folder D:\Programs\mingw64 and choosing [Select folder]). I also got the error message

Undefined variable "mex_spkg" or class "mex_spkg.getEnvVarName".
Error in configuremingw

Tried again, with configuremingw('D:\Programs\mingw64'), and got the same error.

Running MATLAB R2017b without admin rights, mex -setup reports:

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:
	 http://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

The MEX compiler also reports error: mex yprime.c gives:

Building with 'MinGW64 Compiler (C)'.
Warning: MinGW compiler is not configured correctly. Please visit Manually Configure MinGW
for MATLAB to configure the MinGW compiler correctly and recompile your source code. 
MEX completed successfully.

Any idea how to fix this, or can we have an un-obfuscated configuremingw.m function, to try and identify the problem, please?

Log in to comment.


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.

  1 Comment

Despite these errors when I closed MATLAB and reopened it the MINGW compiler had been recognised and could be used.

Log in to comment.


Answer by emrah sever on 4 Dec 2017

Thank you. The explanation solved my problem

  0 Comments

Log in to comment.


Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today