由于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以上,歡迎大家繼續補充
新聞熱點
疑難解答