6

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.

Community
  • 1
  • 1
drmuelr
  • 804
  • 1
  • 11
  • 26

1 Answers1

3

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.
Community
  • 1
  • 1
drmuelr
  • 804
  • 1
  • 11
  • 26
  • sounds like you went through a lot of trouble for a such simple thing. Visual Studio supports side-by-side installations, so you can have multiple versions installed at the same time without any issue. All that messing with SDK was also not necessary, VS installs the complete compiler set. In the past you only needed the Win SDK (which is free to download) when didn't own Visual Studio. Of course now VS2013/VS2015 have a "community edition" which is available for free, and includes the full functionality of the pro edition. – Amro Mar 23 '16 at 06:56
  • @Amro: Unfortunately one cannot use the Community edition for compiling code in MATLAB. – JLagana Jan 23 '17 at 12:00
  • 1
    @JLagana really? Technically there's no reason you can't (community edition is practically equivalent to pro version). I imagine it's not hard to manually modify the mex XML config files in `prefdir` so that it detects VS community edition.. I've done it in the past to add a version of Intel compilers which wasn't officially supported at the time: https://gist.github.com/amroamroamro/414abe0b2a6002cd8945. You can take `msvcpp2015.xml` found in `$matlabroot\bin\$arch\mexopts`, and use it as a starting point for community edition saving the modified one as `$prefdir\mex_C++_$arch.xml` – Amro Jan 23 '17 at 13:19
  • @Amro: I meant, the Community edition is not officially supported. There may be workarounds, indeed. – JLagana Jan 23 '17 at 14:13