由于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以上,欢迎大家继续补充
新闻热点
疑难解答