mex setup no longer finds compiler

95 views (last 30 days)
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 (2)

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.
  4 Comments
Claudio Ferrara
Claudio Ferrara on 12 Feb 2022
Hi @zihui lang I have the same problem now. Did you manage to solve the problem?

Sign in to comment.


Chris Marsh
Chris Marsh on 29 Mar 2022
Hi,
I seem to have exactly the same problem.
I was using 2021b quite happily auto generating code from simulink (using VS 2019)
I then had to install 2021a (as another project was using this version)
After this Matlab (2021a or 2021b) cannot find my compiler.
I've tried re-installing everything VS and matlab version and rebooting countless times to no aval.
Help!!!
... 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)'.
Error using mex
Supported compiler not detected. 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.
  3 Comments
John Morgan
John Morgan on 29 Mar 2022
Edited: John Morgan on 29 Mar 2022
It's ok if there's no AutoRun variable; however, I believe the Command Processor folder should be there. This link might help: https://answers.microsoft.com/en-us/windows/forum/all/accidentally-deleted-command-processor-folder-in/2766c101-9e94-42e2-97e9-69def29da767 you may need to do a repair install

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