Mex command (MinGW-w64 Compiler) failed and gcc exited with a return value 1

I followed the tutorial link exactly to install MinGW-w64 Compiler from Add-Ons Menu and then tested it against the example c file yprime.c.
But it turns out that something is wrong with gcc, could anyone shed lights on it?
I am using Windows system. And I have tried manually downloaded the compiler but to no avail.
Any help is much appreciated! Thank you!
Below is the code to reproduce the problem:
And below is what is shown after I run mex -setup -v
Verbose mode is on.
... Looking for compiler 'Intel Parallel Studio XE 2017 with Microsoft Visual Studio 2015 (C)' ...
... Looking for environment variable 'ICPP_COMPILER17' ...No.
Did not find installed compiler 'Intel Parallel Studio XE 2017 with Microsoft Visual Studio 2015 (C)'.
... Looking for compiler 'Intel Parallel Studio XE 2017 with Microsoft Visual Studio 2017 (C)' ...
... Looking for environment variable 'ICPP_COMPILER17' ...No.
Did not find installed compiler 'Intel Parallel Studio XE 2017 with Microsoft Visual Studio 2017 (C)'.
... Looking for compiler 'Intel Parallel Studio XE 2017 with Microsoft Visual Studio 2019 (C)' ...
... Looking for environment variable 'ICPP_COMPILER17' ...No.
Did not find installed compiler 'Intel Parallel Studio XE 2017 with Microsoft Visual Studio 2019 (C)'.
... Looking for compiler 'Intel Parallel Studio XE 2018 with Microsoft Visual Studio 2015 (C)' ...
... Looking for environment variable 'ICPP_COMPILER18' ...No.
Did not find installed compiler 'Intel Parallel Studio XE 2018 with Microsoft Visual Studio 2015 (C)'.
... Looking for compiler 'Intel Parallel Studio XE 2018 with Microsoft Visual Studio 2017 (C)' ...
... Looking for environment variable 'ICPP_COMPILER18' ...No.
Did not find installed compiler 'Intel Parallel Studio XE 2018 with Microsoft Visual Studio 2017 (C)'.
... Looking for compiler 'Intel Parallel Studio XE 2018 with Microsoft Visual Studio 2019 (C)' ...
... Looking for environment variable 'ICPP_COMPILER18' ...No.
Did not find installed compiler 'Intel Parallel Studio XE 2018 with Microsoft Visual Studio 2019 (C)'.
... Looking for compiler 'Intel Parallel Studio XE 2019 with Microsoft Visual Studio 2015 (C)' ...
... Looking for environment variable 'ICPP_COMPILER19' ...No.
Did not find installed compiler 'Intel Parallel Studio XE 2019 with Microsoft Visual Studio 2015 (C)'.
... Looking for compiler 'Intel Parallel Studio XE 2019 with Microsoft Visual Studio 2017 (C)' ...
... Looking for environment variable 'ICPP_COMPILER19' ...No.
Did not find installed compiler 'Intel Parallel Studio XE 2019 with Microsoft Visual Studio 2017 (C)'.
... Looking for compiler 'Intel Parallel Studio XE 2019 with Microsoft Visual Studio 2019 (C)' ...
... Looking for environment variable 'ICPP_COMPILER19' ...No.
Did not find installed compiler 'Intel Parallel Studio XE 2019 with Microsoft Visual Studio 2019 (C)'.
... Looking for compiler 'MinGW64 Compiler (C)' ...
... Looking for environment variable 'MW_MINGW64_LOC' ...Yes ('C:\ProgramData\MATLAB\SupportPackages\R2019b\3P.instrset\mingw_w64.instrset').
... Looking for file 'C:\ProgramData\MATLAB\SupportPackages\R2019b\3P.instrset\mingw_w64.instrset\bin\gcc.exe' ...Yes.
... Looking for folder 'C:\ProgramData\MATLAB\SupportPackages\R2019b\3P.instrset\mingw_w64.instrset' ...Yes.
Found installed compiler 'MinGW64 Compiler (C)'.
... Looking for compiler 'Microsoft Visual C++ 2015 (C)' ...
... Looking for registry setting 'HKLM\SOFTWARE\Microsoft\VisualStudio\SxS\VC7' 14.0 ...No.
... Looking for registry setting 'HKCU\SOFTWARE\Microsoft\VisualStudio\SxS\VC7' 14.0 ...No.
... Looking for registry setting 'HKLM\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\SxS\VC7' 14.0 ...No.
... Looking for registry setting 'HKCU\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\SxS\VC7' 14.0 ...No.
Did not find installed compiler 'Microsoft Visual C++ 2015 (C)'.
... Looking for compiler 'Microsoft Visual C++ 2017 (C)' ...
... Looking for registry setting 'HKLM\SOFTWARE\Microsoft\VisualStudio\SxS\VS7' 15.0 ...No.
... Looking for registry setting 'HKCU\SOFTWARE\Microsoft\VisualStudio\SxS\VS7' 15.0 ...No.
... Looking for registry setting 'HKLM\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\SxS\VS7' 15.0 ...No.
... Looking for registry setting 'HKCU\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\SxS\VS7' 15.0 ...No.
Did not find installed compiler 'Microsoft Visual C++ 2017 (C)'.
... Looking for compiler 'Microsoft Visual C++ 2019 (C)' ...
... Looking for environment variable 'ProgramFiles(x86)' ...Yes ('C:\Program Files (x86)').
... Looking for file 'C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe' ...Yes.
... Executing command '"C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe" -version "[16.0,17.0)" -products Microsoft.VisualStudio.Product.Enterprise -property installationPath -format value' ...No.
... Looking for environment variable 'ProgramFiles(x86)' ...Yes ('C:\Program Files (x86)').
... Looking for file 'C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe' ...Yes.
... Executing command '"C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe" -version "[16.0,17.0)" -products Microsoft.VisualStudio.Product.Professional -property installationPath -format value' ...No.
... Looking for environment variable 'ProgramFiles(x86)' ...Yes ('C:\Program Files (x86)').
... Looking for file 'C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe' ...Yes.
... Executing command '"C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe" -version "[16.0,17.0)" -products Microsoft.VisualStudio.Product.Community -property installationPath -format value' ...No.
Did not find installed compiler 'Microsoft Visual C++ 2019 (C)'.
... Looking for compiler 'MinGW64 Compiler (C)' ...
... Looking for environment variable 'MW_MINGW64_LOC' ...Yes ('C:\ProgramData\MATLAB\SupportPackages\R2019b\3P.instrset\mingw_w64.instrset').
... Looking for file 'C:\ProgramData\MATLAB\SupportPackages\R2019b\3P.instrset\mingw_w64.instrset\bin\gcc.exe' ...Yes.
... Looking for folder 'C:\ProgramData\MATLAB\SupportPackages\R2019b\3P.instrset\mingw_w64.instrset' ...Yes.
Found installed compiler 'MinGW64 Compiler (C)'.
MEX configured to use 'MinGW64 Compiler (C)' for C language compilation.
To choose a different language, select one from the following:
mex -setup C++
mex -setup FORTRAN

 Accepted Answer

I can answer my own question then, with the help of Aditya Mittal from MathWorks Technical Support.
It turns out that not disabling AutoRun feature properly is the issue.
After running the following command in cmd window
winqueryreg('HKEY_CURRENT_USER','SOFTWARE\Microsoft\Command Processor','Autorun')
it shows a directory that no longer exists! (in my case, it is "D:\Download\Anaconda1\condabin\conda_hook.bat", but I uninstalled the Anaconda recently)
After I follow the HKEY_CURRENT_USER\SOFTWARE\Microsoft\Command Processor path and clear the registry entry, everything is fine now!
Great appreciation for the MathWorks Technical Support!

4 Comments

can you elaborate a bit more, please? I'm having the same problem and I'm not sure I got what your solution procedure exactly was.
Thanks!
Hi, @matlab_addicted, thanks for asking.
I would just first elaborate on my solution and I will paste the rest of the emails I got from the technical support for you to find other potential problems.
First running winqueryreg('HKEY_CURRENT_USER','SOFTWARE\Microsoft\Command Processor','Autorun') from inside Matlab (I did not say it clearly in the original answer), and check if it returns anything. If there is, refer to the following step:
  • Assuming you are using Windows system, press windows + R and type regedit.exe to open the registry. Follow the directory path as the picture shows; clear the Data entry of Autorun if possible (now I do not have anything to delete).
If there is nothing returned from the winqueryreg command, I could only copy paste what I heard from the technical support.
------------------------------------------------------------------------------------------------------------------------------
Please follow the below troubleshooting steps and let me know if it resolves the issue:
1) Confirm that the correct version of MinGW is installed for the version of MATLAB being used. One way to do this is to enter the following in MATLAB command window:
%The code below navigates to the install location of MinGW and executes the 'gcc' command
>> pathToMinGW = getenv('MW_MINGW64_LOC');
>> cd( fullfile(pathToMinGW, 'bin') );
>> !gcc --version
2) Try using the 'gcc' command directly to compile a test file
>> !gcc test_program.c
In this case, running 'gcc' manually produces the following error:
"application was unable to start correctly (0x00000022),..."
From this, it appears that something went wrong in the installation.
Uninstall the support package and any versions of MinGW from the server and try reinstalling the support package. If this is for an offline machine, refer to the link below:
NOTE: It is possible that antivirus software could interfere with the installation of the support package. If you are aware of any antivirus software operating on the server, please temporarily disable it, or white-list both MATLAB and the support package installer, before continuing with the installation.
------------------------------------------------------------------------------------------------------------------------------
Please check the output after executing the following command in the MATLAB command window:
>> mex -v -setup
I expect that this will return some error. This error is due to AutoRun setting in Microsoft command processor. Deleting the Autorun registry attribute resolved the issue.
Please refer the following link to disable autorun in windows.
The actual call to MinGW64 can have worked fine then, producing a valid MEX-file but if the AutoRun part caused an error, the return code would be non-zero making MATLAB throw a warning or even think the command failed.
------------------------------------------------------------------------------------------------------------------------------
Note: 3. is my problem
1. What is the full output when you compiles your MEX-file using "mex" with the -v flag (not "mex -setup -v" but -v with the real compilation "mex -v yourFunction.c")
2. If you open a Windows cmd.exe prompt in general in Window, what does that look like exactly after starting it. Please send a screenshot.
3. Please double check AutoRun options from inside MATLAB, what do the following two commands return?
winqueryreg('HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Command Processor','Autorun')
winqueryreg('HKEY_CURRENT_USER','SOFTWARE\Microsoft\Command Processor','Autorun')
------------------------------------------------------------------------------------------------------------------------------
Let me know if it resolves the issue. And if not, you could fire up an application to contact MathWorks Technical Support (they are really helpful!) and get more technical help for your specific problem.
Hi @Xinchen Zhang thanks, I gave a try, but I was wrong. This does not seem to be my problem.
Thanks though!
Fantastic!
The same problem occured and has been solved by following your answer. With my case, the Data of Autorun was 'if exist '. I just deleted the data and problem fixed.
Thanks a lot!

Sign in to comment.

More Answers (0)

Categories

Products

Release

R2019b

Tags

Community Treasure Hunt

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

Start Hunting!