matlab2013不支持vs2013,因此使用
mex -setup
会提示无法找到编译器
解决方法很简单,思路就是vs2013和vs2012在c++编译器部分应该基本一样。
1、在setup后选择N
Would you like mex to locate installed compilers [y]/n? n
Select a compiler:
[1] Intel C++ 13.0 (with Microsoft Software Development Kit (SDK) linker)
[2] Intel C++ 13.0 (with Microsoft Visual C++ 2010 linker)
[3] Intel C++ 13.0 (with Microsoft Visual C++ 2012 linker)
[4] Intel C++ 12.0 (with Microsoft Software Development Kit (SDK) linker)
[5] Intel C++ 12.0 (with Microsoft Visual C++ 2008 SP1 linker)
[6] Intel C++ 12.0 (with Microsoft Visual C++ 2010 linker)
[7] Intel Visual Fortran 13 (with Microsoft Software Development Kit (SDK) linker)
[8] Intel Visual Fortran 13.0 (with Microsoft Visual C++ 2010 linker)
[9] Intel Visual Fortran 13.0 (with Microsoft Visual C++ 2012 linker)
[10] Intel Visual Fortran 12 (with Microsoft Software Development Kit (SDK) linker)
[11] Intel Visual Fortran 12.0 (with Microsoft Visual C++ 2008 SP1 linker)
[12] Intel Visual Fortran 12.0 (with Microsoft Visual C++ 2008 Shell linker)
[13] Intel Visual Fortran 12.0 (with Microsoft Visual C++ 2010 linker)
[14] Microsoft Software Development Kit (SDK) 7.1
[15] Microsoft Visual C++ 2005 SP1
[16] Microsoft Visual C++ 2008 SP1
[17] Microsoft Visual C++ 2010
[18] Microsoft Visual C++ 2012
Would you like mex to locate installed compilers [y]/n? n
Select a compiler:
[1] Intel C++ 13.0 (with Microsoft Software Development Kit (SDK) linker)
[2] Intel C++ 13.0 (with Microsoft Visual C++ 2010 linker)
[3] Intel C++ 13.0 (with Microsoft Visual C++ 2012 linker)
[4] Intel C++ 12.0 (with Microsoft Software Development Kit (SDK) linker)
[5] Intel C++ 12.0 (with Microsoft Visual C++ 2008 SP1 linker)
[6] Intel C++ 12.0 (with Microsoft Visual C++ 2010 linker)
[7] Intel Visual Fortran 13 (with Microsoft Software Development Kit (SDK) linker)
[8] Intel Visual Fortran 13.0 (with Microsoft Visual C++ 2010 linker)
[9] Intel Visual Fortran 13.0 (with Microsoft Visual C++ 2012 linker)
[10] Intel Visual Fortran 12 (with Microsoft Software Development Kit (SDK) linker)
[11] Intel Visual Fortran 12.0 (with Microsoft Visual C++ 2008 SP1 linker)
[12] Intel Visual Fortran 12.0 (with Microsoft Visual C++ 2008 Shell linker)
[13] Intel Visual Fortran 12.0 (with Microsoft Visual C++ 2010 linker)
[14] Microsoft Software Development Kit (SDK) 7.1
[15] Microsoft Visual C++ 2005 SP1
[16] Microsoft Visual C++ 2008 SP1
[17] Microsoft Visual C++ 2010
[18] Microsoft Visual C++ 2012
2、选vs2012 即18
3、把默认目录改成vs2013的目录
Use C:\Program Files (x86)\Microsoft Visual Studio 11.0 anyway [y]/n? n
Please enter the location of your compiler: [C:\Program Files (x86)\Microsoft Visual Studio 11.0] C:\Program Files (x86)\Microsoft Visual Studio 12.0
Use C:\Program Files (x86)\Microsoft Visual Studio 11.0 anyway [y]/n? n
Please enter the location of your compiler: [C:\Program Files (x86)\Microsoft Visual Studio 11.0] C:\Program Files (x86)\Microsoft Visual Studio 12.0
4、安装成功
编译的时候可能出现lib文件找不到问题:
LINK : fatal error LNK1181: cannot open input file 'gdi32.lib'
LINK : fatal error LNK1181: cannot open input file 'gdi32.lib'
大概查了一下发现是编译器的升级,在win8、vs2013下这个已经没有了,根本不需要。因此直接删了就行。
找到
C:\Users\****\AppData\Roaming\MathWorks\MATLAB\R2013b
C:\Users\****\AppData\Roaming\MathWorks\MATLAB\R2013b
右键编辑 mexopts.bat,把对应行改成这样:(删掉除了kernel32.lib 与user32.lib 之后的所有lib)
set LINKFLAGS=/dll /export:%ENTRYPOINT% /LIBPATH:"%LIBLOC%" libmx.lib libmex.lib libmat.lib /MACHINE:X64 kernel32.lib user32.lib /nologo /manifest
set LINKFLAGS=/dll /export:%ENTRYPOINT% /LIBPATH:"%LIBLOC%" libmx.lib libmex.lib libmat.lib /MACHINE:X64 kernel32.lib user32.lib /nologo /manifest
再编译就成功了!
转自:http://blog.csdn.net/keithsky/article/details/20306397