How can I get MatLab to find the Visual C++ Compiler?

drmuelr picture drmuelr · Feb 25, 2016 · Viewed 11.2k times · Source

Preamble: I found a solution in the midst of writing this, and this problem was a PITA and had a convoluted solution. Thus, I feel compelled leave this here to help any poor soul who has this problem.


I'm new to MatLab, and I don't usually use Visual C++ either, so forgive me if this should be painfully obvious.

Short version: I have Visual C++ 2013 installed on my computer, but mex can't find it when I run mex -setup c++. I get the following:

>>mex -setup cxx

Error using mex

No supported compiler or SDK was found. You can install the freely available MinGW-w64 C/C++ compiler; see Install MinGW-w64 Compiler. For more options, see http://www.mathworks.com/support/compilers/R2015b/win64.html.


Here's the full situation.

  • OS: Windows 10 Home
  • Compiler: Visual Studio 2013 (v120, up-to-date)
    • I confirmed that I can compile and run a program using this toolset.
  • MatLab version: 2015b

I was originally running Visual Studio 2015, and mex found the compiler just fine. However, I soon found out that Simulink is not compatible with VS 2015, so I had to roll back to VS 2013, and this is when my problem started.

I've tried, among many others, the following sites to find a solution:

Then I went down a rabbit hole.

  1. A very protracted mathworks.com answer that suggested other links. This led me to...

  2. Another mathworks.com answer which sounds like my problem, and suggests patching my setup. Turns out that I don't have SDK 7.1 installed. So, I went to install, and got this error:

    Some components could not be installed. Some Windows SDK components require the RTM .NET Framework 4...

  3. This Stack Overflow question asks about this issue, and I hit the exact same issue Danilo Gadêlha had in regards to the .NET Framework already being installed.

    I tried the top answer, and after removing every single reference to .NET framework of any version I could find, including those under "Windows Features", I still couldn't install.

    I tried the next option, and even in safe mode, RegEdit wouldn't let me change the values suggested by the next answer, so that was a bust.

    Lastly, I tried MandM's solution, which finally solved my chain of problems.

Answer

drmuelr picture drmuelr · Feb 25, 2016

I think this was the root of my problem: when I uninstalled Visual Studio 2015 and installed Visual Studio 2013, an installation or registry setting was left in an incorrect state, and mex was unable to find Visual Studio 2013 as a result.

The solution that worked for me:

  1. Leave Visual Studio 2013 installed.
  2. As MandM answered:

    Uninstall the following:

    • "Microsoft Visual C++ 2010 x64 Redistributable"
    • "Microsoft Visual C++ 2010 x86 Redistributable"

    Before installing the Windows 7.1 SDK, and the install package reinstalls those two during installation.

    As Robert Važan points out in the comments:

    If error message persists despite this workaround, just click OK and proceed with installation. The installation will succeed this time..

    I did get this error, but the install worked fine.

  3. Install the SDK 7.1 Patch, which fixes the issue highlighted on this mathworks.com answer.