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

4.278 Ansichten (letzte 30 Tage)
I already have MinGW on my computer. How do I configure it to work with MATLAB?

Akzeptierte Antwort

MathWorks Support Team
MathWorks Support Team am 10 Aug. 2023
Bearbeitet: MathWorks Support Team am 17 Aug. 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.
Note: 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 the appropriate version of MinGW-w64 according to your version of MATLAB before following the steps below.
  • MinGW-w64 version 8.1 for R2023a and later
  • MinGW-w64 version 6.3 for R2018b and later
  • MinGW-w64 version 5.3 for R2017b through R2018a
1) Start MATLAB with administrative privileges.
2) Download the attached MATLAB function 'configuremingw'.
3) In the MATLAB Command Window run:
>> configuremingw(folder)
where 'folder' is the installation directory of MinGW, for example, 'C:\TDM-GCC-64'. Note that this path should not contain any spaces.
Alternatively, run:
>> configuremingw
Then navigate to the installation directory of MinGW.

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.
Option A: Set "MW_MINGW64_LOC" as a system environment variable on Windows 10/11:
  1. Make sure you have administrative privileges.
  2. Enter "Edit the system environment variables" in the Windows search.
  3. Click "Environment Variables...".
  4. Under System variables, select "New...".
  5. In the New System Variable dialog box, type MW_MINGW64_LOC in the Variable name field.
  6. In the Variable value field, type the location of the MinGW-w64 compiler installation, for example, C:\TDM-GCC-64.
  7. Click "OK" to close the dialog boxes, then close the Control Panel dialog box.
.
Option B: Set "MW_MINGW64_LOC" 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' (note that this path should not contain any spaces). 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.

Verify that the existing MinGW installation is recognized by MATLAB:

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.
  5 Kommentare
Walter Roberson
Walter Roberson am 9 Mai 2023
Both R2021a and R2021b support MinGW 6.3 64 bit
The message appears to be saying that package needs a MinGW 32 bit . That might potentially hint that the version of the package you are using might not be compatible with 64 bit MATLAB -- it depends what it needs the compiler for.
Walter Roberson
Walter Roberson am 10 Mai 2023
Bearbeitet: Walter Roberson am 10 Mai 2023
https://azrael.digipen.edu/~mmead/www/public/mingw/ has instructions for installing the 32 bit version.
CANoe_MatlabIntegrationPackage_MinGW_32_bin appears to be part of CANoe configuration, not MATLAB, so you might need to redo some CANoe installation steps.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (3)

Paul Wintz
Paul Wintz am 16 Aug. 2021
Verschoben: Stefanie Schwarz am 10 Aug. 2023
The instruction the description of MINGWROOT as the "MinGW installation directory containing the MinGW compiler binaries" is confusing. I thought, initally, that the path would include the bin folder (after all, that is where the binaries are located). To the contrary, however, MINGWROOT should point to the parent directory of bin.
So I needed to set MINGWROOTC to \mingw\mingw64 not C:\mingw\mingw64\bin.

Zhibin Deng
Zhibin Deng am 15 Mai 2023
Verschoben: Stefanie Schwarz am 10 Aug. 2023
I got an error
"Error using configuremingw
Unable to setup the MinGW compiler due to administrator privileges not granted."
My matlab version is 2023a under Windows 11. I have run matlab using in the administrative mode.
How to solve this issue?

Richard Crozier
Richard Crozier am 20 Jan. 2020
Verschoben: Stefanie Schwarz am 10 Aug. 2023
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.
  1 Kommentar
Stefanie Schwarz
Stefanie Schwarz am 10 Aug. 2023
Since you appear to have an existing installation of the MinGW Support Package, it is much easier if you just edit the system environment variable MW_MINGW64_LOC in the Windows settings (with the help of an admin) to have this value:
C:\Program Files\mingw-w64\x86_64-6.3.0-posix-seh-rt_v5-rev2\mingw64
Instead of:
C:\ProgramData\MATLAB\SupportPackages\R2018a\3P.instrset\mingw_w64.instrset
(which is where the MinGW compiler shipped with the support package resides).
Then, restart MATLAB.

Melden Sie sich an, um zu kommentieren.

Produkte


Version

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by