如何让 MatLab 找到 Visual C++ 编译器?

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

前言:我在写这篇文章的过程中找到了一个解决方案,这个问题是一个PITA并且有一个复杂的解决方案。因此,我觉得有必要把它留在这里以帮助任何遇到这个问题的可怜人。


我是 MatLab 的新手,而且我也不经常使用 Visual C++,如果这很明显,请原谅我。

精简版:我的电脑上安装了Visual C++ 2013,但是当我运行 mex -setup c++时mex找不到它。我得到以下信息:

>>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.


这是完整的情况。

我本来是运行ning Visual Studio 2015的,mex发现编译器就好了。然而,我很快发现 Simulink 与 VS 2015 不兼容,所以我不得不回滚到 VS 2013,这就是我的问题开始的时候。

除其他外,我还尝试了以下网站来寻找解决方案:

然后我进了一个兔子洞。

  1. A very protracted mathworks.com answer that suggested other links。这导致我...

  2. Another mathworks.com answer 这听起来像我的问题,并建议修补我的设置。原来我没有安装 SDK 7.1。所以,我去安装,得到了这个错误:

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

  3. asks about this issue, and I hit the exact same issue Danilo Gadêlha 已经安装了 .NET Framework。

    我尝试了 ,在删除了我能找到的 任何 版本(包括 "Windows Features" 下的所有对 .NET 框架的引用之后,我仍然无法安装。

    我尝试了 ,即使在安全模式下,RegEdit 也不会让我更改下一个答案建议的值,所以失败了。

    最后,我尝试了 最终 解决了我的一系列问题。

我认为这是我问题的根源:当我卸载 Visual Studio 2015 并安装 Visual Studio 2013 时,安装或注册表设置处于不正确的状态,mex 无法结果找到 Visual Studio 2013。

对我有用的解决方案:

  1. 安装 Visual Studio 2013。
  2. :

    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.

    正如 Robert Važan 在评论中指出的那样:

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

    我确实遇到了这个错误,但安装工作正常。

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