MATLAB Answers

mex setup no longer finds compiler

19 views (last 30 days)
John Morgan
John Morgan on 29 Jan 2021
Answered: John Morgan on 24 Feb 2021
I use Matlab 2019a and 2020b on Windows 10 with Visual Studio 2019. In the past I was able to build mex code, but now I can no longer find a compiler. The following changes might be relevant:
  • Updated Microsoft Visual Studio Professional 2019 to version 16.8.4
  • Installed Matlab Compiler on Matlab 2020b (no changes were made to 2019a, but it no longer works either)
After looking into this, it seems that calls to cmdReturns in msvcpp2019.xml always fail, and I haven't been able to find anyone with a similar issue. Here is the relevant output from mex -v -setup cpp:
... Looking for compiler 'Microsoft Visual C++ 2019' ...
... 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'.
The call to vswhere.exe is failing; however, if I run the same command in a command prompt I do get output:
C:\>"C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe" -version "[16.0,17.0)" -products Microsoft.VisualStudio.Product.Professional -property installationPath -format value
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional
To eliminate vswhere as the culprit, I added the following lines to msvcpp2019.xml:
<cmdReturns name="echo hello" />
<cmdReturns name="call echo hello" />
Which returns:
... Executing command 'echo hello' ...No.
... Executing command 'call echo hello' ...No.
So, it seems that cmdReturns always fails. What could be causing this?

Accepted Answer

John Morgan
John Morgan on 24 Feb 2021
I've finally fixed this! I noticed that whenever I started up a command pompt, the following appeared at the top of the window:
Microsoft Windows [Version 10.0.18363.1379]
(c) 2019 Microsoft Corporation. All rights reserved.
The system cannot find the path specified.
After searching for what could be causing the "The system cannot find the path specified." message I came across the advice to clear the following registry values:
  • HKEY_CURRENT_USER\Software\Microsoft\Command Processor\AutoRun
  • HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\AutoRun
For me, the first value was populated with a conda_hook.bat file that didn't exist. After clearing the value, Matlab is able to find my compiler.

More Answers (1)

Suryaansh Mata
Suryaansh Mata on 18 Feb 2021
The issue looks similar to the one below. Give a try to the steps suggested for the same.
Additionally, this might be due to issues with the key in the registry or environment variables. Reinstallation should add the right key in the registry and set the required env var
DISCLAIMER: These are my own views and in no way depict those of MathWorks.
  2 Comments
John Morgan
John Morgan on 18 Feb 2021
I tried reinstalling and still get the same issue. I did the following:
  1. Repair my Visual Studio installation
  2. Reboot
  3. Uninstall Matlab 2019a
  4. Reboot
  5. Uninstall Matlab 2020b
  6. Reboot
  7. Install Matlab 2020b to C:\MATLAB\R2020b

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!