MATLAB: How to work around the issue of not able to use MinGW and Windows SDK 10 for Excel Add-in Deployment because of mbuild.bat failure in R2018a

add-incompilerexcelMATLAB Compilermbuild

I am trying to use MinGW and Windows SDK 10 compiler combination to compile an Excel Add-in, I have installed MinGW and Windows 10 SDK, but when I execute the compiler configuration command:
>> mbuild -setup -client mbuild_com -v
I got the following snippet:
... Looking for compiler 'MinGW64 Compiler (C++)' ...
... Looking for environment variable 'MW_MINGW64_LOC' ...Yes ('C:\mingw64').
... Looking for file 'C:\mingw64\bin\g++.exe' ...Yes.
... Looking for folder 'C:\mingw64' ...Yes.
... Looking for environment variable 'MW_MINGW64_LOC' ...Yes ('C:\mingw64').
... Executing command 'C:\mingw64\bin\g++ -dumpmachine' ...Yes ('x86_64-w64-mingw32').
Found installed compiler 'MinGW64 Compiler (C++)'.
... Looking for compiler 'MinGW64 Compiler with Windows 10 SDK or later (C++)' ...
... Looking for environment variable 'MW_MINGW64_LOC' ...Yes ('C:\mingw64').
... Looking for file 'C:\mingw64\bin\g++.exe' ...Yes.
... Looking for folder 'C:\mingw64' ...Yes.
... Looking for registry setting 'HKLM\SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows\v10.0' InstallationFolder ...Yes ('C:\Program Files (x86)\Windows Kits\10\').
... Looking for folder 'C:\Program Files\MATLAB\R2018a' ...Yes.
... Executing command '"C:\Program Files\MATLAB\R2018a\bin\mbuild.bat" -getWin10SDKVersion' ...No.
It seems that MATLAB failed to find the compiler because the last line returned 'No'.

Best Answer

The reasons that it returns "No" for the execution of the batch script function:
"C:\Program Files\MATLAB\R2018a\bin\mbuild.bat" -getWin10SDKVersion
are most likely caused by the following:
1. The Windows SDK 10 is not properly installed.
Please check under the Windows SDK 10 installation folder, which by default should be under 'C:\Program Files (x86)\Windows Kits\10\', the existence of a file Windows.h under C:\Program Files (x86)\Windows Kits\10\\include\10.0.xxxxx.0\um folder. Please note that "10.0.xxxxx.0" is a subfolder name that contains the subversion number in replace of the "xxxxx".
If you do not find the Windows.h file under the directory, you might not have Windows SDK 10 properly installed, please reinstall it from Microsoft's website here.
2. There is a system group policy on the machine that restricts the execution of batch files.
This will prevent the batch script function to be executed correctly, so MATLAB would not able to identify the compiler.
Please follow the step below if the Windows SDK 10 is properly installed and this is believed to be the issue:
a. Please find the attached file "mingw64_g++_sdk10+.xml", download it to a temporary directory.
b. Please open a file explorer and go to the directory at <matlabroot>
\bin\win64\mexopts, where <matlabroot> is the MATLAB installation directory, which can be found out by execute the following in MATLAB command window:
>> matlabroot
Please move the existing file "mingw64_g++_sdk10+.xml" to another location for backup, and copy the downloaded attachment file into the directory.
c. Please open a file explore and direct to the following directory:
C:\Users\<username>\AppData\Roaming\MathWorks\MATLAB\<matlab version>
where <username> 
is the user logs into the PC and <matlab version> is the release number such as R2018a.
Please note "AppData" is a hidden folder, you may make changes and directly copy it to the directory path in file explore to access it.
Please then delete the file "MBUILD_COM_C++_win64.xml" in the directory if it exists.
d. Please execute the following "mbuild" configuration command in MATLAB and you may proceed with the compilation if it recognizes the compilers correctly:
>> mbuild -setup -client mbuild_com -v