Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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:

  • The MatLab mex documentation - No help, only shows basic mex usage.
  • The MatLab supported compiler list - Confirmed that VC++ 2013 is compatable.

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.

like image 471
drmuelr Avatar asked Feb 25 '16 05:02

drmuelr


People also ask

How do I find the compiler in MATLAB?

Select Microsoft Visual Studio Compiler MATLAB displays information about this compiler, which remains the default until you call mex -setup cpp to select a different default.

How do I know which compiler I am using in Visual Studio?

The exact name depends on which version of Visual Studio or the Visual Studio Build Tools you have installed. Select the item to open the prompt. You can test that you have the C++ compiler, cl.exe , installed correctly by typing 'cl' and you should see a copyright message with the version and basic usage description.

Where is the Visual Studio compiler?

As explained above, the Microsoft C/C++ compiler is part of the Windows SDK and is natively included within your Visual Studio installation. More precisely, the default path where you'll find the compiler is C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin . The compiler is cl.exe .

How do I know if Visual C++ compiler is installed?

So if you ever need to check the version of the GCC C++ compiler that you have installed on your PC, you can do it through the command prompt by typing in the single line, g++ --version, and this will return the result. So this is how to check the version of the GCC C++ compiler installed in windows.


1 Answers

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.
like image 179
drmuelr Avatar answered Sep 18 '22 04:09

drmuelr