【Matlab】Matlab R2014a 64位与Visual Studio2015的mex相关问题

来源:互联网 发布:二叉树的结点算法 编辑:程序博客网 时间:2024/04/28 16:16

由于C语言的高效性,在matlab中会经常需要调用C语言的衍生程序,所以用到mex。但是mex -setup中,MatlabR2014a在官方给出的文档中,最高仅支持到VS2013。这让用VS2015和MatlabR2014a的我们会很头疼的一件事情。然而网上对这一方面的资料的好像比较少,通过google和各种百度,整理下面方法供大家参考一下

本文给出的方法仅仅面对MatlabR2014a 64位 与 Visual Studio2015,win10 环境

当mex -setup(注意存在空格)时,弹出:

Error using mex No supported compiler or SDK was found. For options,
visit http://www.mathworks.com/support/compilers/R2014a/win64.

那么打开下面网址则可看到:
这里写图片描述

打开相应版本的supported compilers的detail,选择下载下面的win sdk
这里写图片描述

当安装完SDK后,再在matlab中敲入 mex -setup,则会弹出warning,显示没有合适的compilers。(应该类似下图,当时我忘记截图了,囧)

>> mex -setup Warning: Windows SDK 7.1 appears to be installed, but its compiler was not found. Install .NET Framework 4.0, and then rerun the SDK installation to add the "Visual C++ Compilers" component. See http://www.mathworks.com/support/solutions/en/data/1-IB1G3Q/ for more information. 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.

这里好像是因为下载的win sdk7.1是.net Framework4的,而win10的版本应该在.NET Framework 4.6,所以在这里出现一点问题。
这里写图片描述
具体参考:
https://cn.mathworks.com/matlabcentral/answers/279692-why-does-microsoft-windows-sdk-7-1-not-get-detected-as-a-supported-compiler-for-windows-10-with-fram

当下载完上述网站给的链接后,matlab应该可以正常mex了

>> mex -setupMEX 配置为使用 'Microsoft Windows SDK 7.1 (C)' 以进行 C 语言编译。Warning: The MATLAB C and Fortran API has changed to support MATLAB     variables with more than 2^32-1 elements. In the near future     you will be required to update your code to utilize the     new API. You can find more information about this at:     http://www.mathworks.com/help/matlab/matlab_external/upgrading-mex-files-to-use-64-bit-api.html.要选择不同的语言,请从以下选项中选择一种命令: mex -setup C++  mex -setup FORTRAN

以上,欢迎大家继续补充

==============================================================
==============2017年3月6日更新==============================================================
有个好友也出现了这个问题,我也将其整理如下:
他的配置如下:MATLAB2016b VS2008 MinGW4.9.2 win7 64位
由于Matlab2016b并不支持VS2008,所以他已经下载好MinGW4.9.2
然而mex出现如下问题:
这里写图片描述

由于他已经安装好MinGW,所以本人感觉应该是SDK的问题。
于是他选择安装了SDK,链接如下:
https://www.microsoft.com/en-us/download/details.aspx?id=8279

于是便可以正常编译了,如下图:
这里写图片描述

**以上
欢迎大家指正补充**

2 0
原创粉丝点击