mex setup no longer finds compiler

60 views (last 30 days)
John Morgan
John Morgan on 29 Jan 2021
Commented: zihui lang on 14 Jan 2022 at 16:12
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.
  3 Comments
zihui lang
zihui lang on 14 Jan 2022 at 16:12
Hi there, I have a similar issue to John's but mine probabaly easier to solve. In my case, if I put the
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
in my cmd. It won't gives me any return. I re-install my visual studio for several times and makes sure I'm including the vs2019 builder (MSDV v142) but this problem still shows up. When I put
mex -setup -v
in my matlab, here is what it returns.
... 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)'.
I believe this is because my vswhere.exe is not working properly, but how should I fix it?
Thanks and looking forward to your reply,
Best,
Zihui

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by