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

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.
A very protracted mathworks.com answer that suggested other links. This led me to...
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...
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.

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:
Leave Visual Studio 2013 installed.
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.
Install the SDK 7.1 Patch, which fixes the issue highlighted on this mathworks.com answer.

Related

Where can I find if the Visual C++ components or the Microsoft Visual C++ Build Tools are installed in Visual Studio 2015?

I guess I may be getting into trouble for asking ironically obvious questions. I had found the place that shows where things are installed on Visual Studio 2015 in 2016, but now I can't remember where it is. I see instructions of how to check using the command line, although I saw a nifty place that showed me which components were installed somewhere in the toolbars on top in 2016. Funny.

Visual Studio 2017 wont show c++ template/extansion

I am trying to use Microsoft visual studio IDE to run my c++ code, however, when I go to create a project, I do not see the option for a c++ project. I tried reinstalling the program to see if I could somehow install the package/extension however it just won't seem to come up.
The only templates that appear are in c# or f#.
If someone could please lead me into the right direction so that I can fix this, it would be great. Thank you.
I don't see any mention of C++ in the release notes.
According to this post on MSDN, there is no C++ support in the Mac version of Visual Studio. It contains links to instructions for using Visual Studio Code, as well as the option to install a VM running Windows.
Apparently Visual Studio Code supports C++ projects, since it can execute external tools. The Microsoft Visual C++ build tools are free for Windows, but I don't think there is a version for the Mac, so some other external compiler is necessary.

How to ensure Visual studio updates the registry when installing compiler

I'm having a frustrating time trying to get the visual studio compiler up and running. I'm trying to install the visual studio compiler to use with matlab.
After installing build tools from here, for some reason, the registry is not updated and matlab is not able to find the compiler. I tried uninstalling and reinstalling after cleaning the registry using ccleaner but that doesn't seem to be working. Any suggestions on what I might be doing wrong? Any help will be much appreciated.
Turns out the new version of visual studio 2017 doesn't actually update the registry or something like that (see here: https://developercommunity.visualstudio.com/content/problem/2813/cant-find-registry-entries-for-visual-studio-2017.html) .
I ended up installing the older version of visual studio community (VS 2015 with updates) and matlab was able to find it.

Install Visual C++ Compiler on Windows without installing whole Visual Studio

NOTE This question can be duplicate of this or this question.
But please don't close it as duplicate without reading entire question.
I'm trying to install npm module browsersync on Windows, and by reading its documentation, I found that module itself uses node-gyp which requires C++ compiler on Windows to build native extension. And that leads to installation of Visual Studio (community edition will do). After going through above linked questions (which I noted as duplicates of my current question), I found that Windows SDK used to ship with C++ compiler but now Visual Studio is required to have C++ compiler.
So my concern is, do I really need to download and install that hefty 6 GB VS Community edition just to get that C++ compiler to build browsersync on Windows? or is there any way to do that via GCC for Windows?
P.S. Earlier I faced similar situation for installing node-oracledb.
Thanks.
#Niall covered where you can get the actual C++ compiler, but if you're looking for further information on the problem there's a walkthrough on how to get node-gyp up and running on Windows on their github issues page with the standalone compiler.

How set C/C++ compiler for matlab?

i've read several topics on this issue... but i'm not still able to figure out.
I've matlab 2013 and "MS Visual C++ 2012 Redistributable" both x86/x64 installed in Windows 8.
When i run "mex -setup" in matlab the following message appear:
Please choose your compiler for building MEX-files:
Would you like mex to locate installed compilers [y]/n? y
No supported SDK or compiler was found on this computer.
For a list of supported compilers, see
http://www.mathworks.com/support/compilers/R2013a/win64.html
but the suggested file is for installing .NET 4 for windows 7, and i've windows 8. However, although i install this framework the mex -setup command still doesn't works.
It seems to still be an issue with no straightforward solution. It took me a lot of searching, reading and trial and error to get a compiler to be recognized by mex.
In a nutshell, matlab 2013 doesn't support windows 8 SDK, but windows 7 SDK does not (easily) install on windows 8.
What worked for me:
The win7 SDK doesn't install on windows 8 because more recent versions of the Visual C++ 2010 Redistributable are already installed by default on Windows 8. You have to manually (from the control panel/programs/uninstal ...) uninstall all flavors of VC++2010 redistributable (x86 and x64).
See this Microsoft article for details on how to do that.
After that I could install the SDK for win7 and got the compiler to be recognized by mex.
Note:
I run on win8 32 bits, so what worked for me may not be perfect for everybody. During my searches on the subject i also noticed that many people often stumbled on 2 other setbacks:
During the setup of win 7 SDK, .NET 4 doesn't install. => This is because .net4.5 is already shipped in windows 8. Again, uninstall .net4.5, then reinstall win7 SDK. (you can even reinstall .net4.5 if necessary after everything is done).
Once everything is installed and mex happily found the compiler, error are raised during compilation tentative about a missing ammintrin.h. You may have to install MS Visual Studio C++ 2010 express then upgrade it to SP1. In this case follow the nicely detailed instructions in this Matlab central article.
This last article linked seem to offer a complete solution, i didn't refer to it first in my answer because in some case (my case for example), only part of the setup described was necessary, so there was no point uninstalling/reinstalling a bunch of stuff. But be prepared that you may have to go though all of it ...