Why is MATLAB unable to find the Microsoft Visual C++ 2017 compiler after installing Microsoft Visual Studio 2017?

I installed Microsoft Visual Studio 2017 Professional, however "mex -setup" still does not successfully find the Microsoft Visual C++ 2017 compiler. This can be seen from the following output when running the command "mex -v -setup":
>> mex -setup -v
... 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 ...Yes ('C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\').
... Executing command 'set "vcroot=C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional"&for /f "delims= " %a in ('type "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.txt"') do @if exist"C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\%a\bin\HostX64\x64\cl.exe" call echo %vcroot%' ...No.
Did not find installed compiler 'Microsoft Visual C++ 2017 (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.
How can I resolve this?

 Accepted Answer

This issue is likely caused by having installed Microsoft Visual Studio 2017 without the required "Desktop development with C++" workload. As a result, the actual C/C++ compiler (cl.exe) is missing from the installation and causes the "mex" command to fail.
Follow these instructions to reinstall and configure Visual Studio 2017:
If the detection still fails, verify that the Windows registry entries are pointing to the correct Visual Studio 2017 installation folder. In the example above, the "15.0" value under the registry key HKCU\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\SxS\VS7 is set to:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\
If the returned location is not as expected, please contact your IT helpdesk to correct the registry entry.

Further Troubleshooting:

If the "Desktop development with C++" workload is installed in your Visual Studio 2017 IDE, and the registry keys are set correctly, then there is most likely a general issue on your PC with issuing commands at the Windows CMD Prompt. This might be caused by invalid AutoRun commands. Verify if there are any invalid commands present in the following registry entries, and remove them:
HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\AutoRun
HKEY_CURRENT_USER\Software\Microsoft\Command Processor\AutoRun
If invalid AutoRun commands are not present, try the following troubleshooting steps:
1. Verify that the "Microsoft.VCToolsVersion.default.txt" file exists at the location indicated by "mex -setup":
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.txt
2. Open this TXT file in an editor. It should not be empty, but contain a list of one or more MSVC version numbers.
3. For all version numbers appearing in the TXT file, look if the file "cl.exe" exists at any of the corresponding locations as indicated by "mex -setup". For example, if the TXT file contains the version number 14.16.27023, look for:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\bin\HostX64\x64\cl.exe
If any of the steps 1-3 fail, you may need to reinstall Visual Studio. Please follow the installation instructions shown in the following MATLAB Answers Post:

Learn more:

For more information, see the Supported Compiler page for your MATLAB release:
For assistance with downloading, installing, and licensing a supported edition of Visual Studio, reach out to your IT helpdesk.

More Answers (0)

Categories

Products

Release

R2018b

Community Treasure Hunt

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

Start Hunting!