Mingw not working for C++ compilation

Hi,
I have installed mingw from add-ons in MATLAB2022b,
when i run command: mex -setup C --> MATLAB detects mingw
but when i run command: mex -setup C++ --> MATLAB is unable to locate it.
version : MinGW-W64-builds-4.3.0

Answers (1)

Hitesh
Hitesh on 16 May 2025
Edited: Hitesh on 16 May 2025
Hi Darshna,
Since you already appeared 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
(which is where the MinGW compiler shipped with the support package resides).
Then, restart MATLAB.
For more information regarding this issue, kindly refer to the following MATLAB Answer:

4 Comments

Darshna
Darshna on 16 May 2025
Edited: Darshna on 16 May 2025
Hi Hitesh,
Thanks for respoding.
Please note that I dont have any mingw related folder at location C:\Program Files\
or C:\Program Files (x86)\
Is this any installation related issue? I installed mingw extension from official MATLAB add ons.
I also tried to uninstall and then install it again, but still got same response.
Hi Darshana,
Could you execute the following command to get the path of the mingw ?
mingwdir = getenv ('MW_MINGW64_LOC')
I too encountered the same error, reinstalling the mingw add-on worked for me, if the issue persists execute the following command.
rehash toolboxcache
Rehashing the toolbox cache updates the list of known files and classes for all folders on the MATLAB Search Path. Please refer to the 'rehash' documentation page for more details.
Hi Hitesh,
Thanks for responding.
I am able to run mingwdir = getenv ('MW_MINGW64_LOC')
So I have followed below sequence: first I uninstalled mingw and run
  1. mex -setup
  2. getenv ('MW_MINGW64_LOC')
  3. rehash toolboxcache
Then i installed mingw from add-ons and again run commands:
  1. mex -setup
  2. getenv ('MW_MINGW64_LOC')
  3. rehash toolboxcache
  4. mex --setup C++
MATLAB could't find compiler for cpp.
Is there any possibility of the rights because I opened MATLAB with different user id?
Hi Darshna,
I think this might be best handled with MathWorks tech support. Could you submit a technical support request?

Sign in to comment.

Asked:

on 15 May 2025

Commented:

on 2 Jun 2025

Community Treasure Hunt

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

Start Hunting!