解决Matlab 2012b中无法选择Visual Studio 2012作为编译器的问题

最近追求时髦,把Matlab 和VS 都换成了最新版,系统暂时没换,还是win7 32位. 下载了libSVM准备在matlab里编译的时候,首先用mex -setup选择编译器,就发现只有matlab自带的lcc的选项,没有vs2012. 而用lcc编译libSVM的时候,总报语法错误。参考了http://download.csdn.net/detail/wiills/4621079 的做法后,发现选择编译器的过程,似乎只是修改C:\Users\(name)\AppData\Roaming\MathWorks\MATLAB\R2012b\mexopts.bat 中参数的过程。只要让matlab知道编译器、lib文件等的位置和一些编译参数,就足够了。

我首先使用了上面的下载,并且按照他的要求修改了文件(修改后的文件见我的资源),之后发现虽然mex -setup 中有了vs2012,但编译mex时还是出问题。这是因为上面的下载适用于x64的系统,如果要改成x86很难把所有需要修改的东西都改好。于是我又修改了C:\Users\(name)\AppData\Roaming\MathWorks\MATLAB\R2012b\mexopts.bat,并且已经测试成功,下面贴出我的修改后的mexopts.bat,供各位遇到matlab找不到vs编译器的学者参考。高亮的是一些需要注意修改的地方:


@echo off
rem MSVC110OPTS.BAT
rem
rem    Compile and link options used for building MEX-files
rem    using the Microsoft Visual C++ compiler version 11.0
rem
rem    $Revision: 1.1.6.4.2.1 $  $Date: 2012/07/12 13:53:59 $
rem    Copyright 2007-2009 The MathWorks, Inc.
rem
rem StorageVersion: 1.0
rem C++keyFileName: MSVC100OPTS.BAT
rem C++keyName: Microsoft Visual C++ 2012
rem C++keyManufacturer: Microsoft
rem C++keyVersion: 11.0
rem C++keyLanguage: C++
rem C++keyLinkerName: Microsoft Visual C++ 2012
rem C++keyLinkerVersion: 11.0
rem
rem ********************************************************************
rem General parameters
rem ********************************************************************


set MATLAB=%MATLAB%
set VSINSTALLDIR=C:\Program Files\Microsoft Visual Studio 11.0
set VCINSTALLDIR=%VSINSTALLDIR%\VC
rem In this case, LINKERDIR is being used to specify the location of the SDK
set LINKERDIR='.registry_lookup("SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.0A" , "InstallationFolder").'
rem set LINKERDIR=C:\Program Files\Windows Kits\8.0A\
set PATH=%VCINSTALLDIR%\bin;%VCINSTALLDIR%\bin;%VCINSTALLDIR%\VCPackages;%VSINSTALLDIR%\Common7\IDE;%VSINSTALLDIR%\Common7\Tools;%LINKERDIR%\bin\x86;%MATLAB_BIN%;%PATH%
set INCLUDE=%VCINSTALLDIR%\INCLUDE;%VCINSTALLDIR%\ATLMFC\INCLUDE;%INCLUDE%
set LIB=%VCINSTALLDIR%\LIB;%VCINSTALLDIR%\ATLMFC\LIB;%MATLAB%\extern\lib\win32\microsoft;C:\Program Files\Microsoft SDKs\Windows\v7.1A\Lib;%LIB%
set MW_TARGET_ARCH=win32


rem ********************************************************************
rem Compiler parameters
rem ********************************************************************
set COMPILER=cl
set COMPFLAGS=/c /GR /W3 /EHs /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /D_SECURE_SCL=0 /DMATLAB_MEX_FILE /nologo /MD
set OPTIMFLAGS=/O2 /Oy- /DNDEBUG
set DEBUGFLAGS=/Z7
set NAME_OBJECT=/Fo


rem ********************************************************************
rem Linker parameters
rem ********************************************************************
set LIBLOC=%MATLAB%\extern\lib\win32\microsoft
set LINKER=link
set LINKFLAGS=/dll /export:%ENTRYPOINT% /LIBPATH:"%LIBLOC%" libmx.lib libmex.lib libmat.lib /MACHINE:X86kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /manifest /incremental:NO /implib:"%LIB_NAME%.x" /MAP:"%OUTDIR%%MEX_NAME%%MEX_EXT%.map"
set LINKOPTIMFLAGS=
set LINKDEBUGFLAGS=/debug /PDB:"%OUTDIR%%MEX_NAME%%MEX_EXT%.pdb"
set LINK_FILE=
set LINK_LIB=
set NAME_OUTPUT=/out:"%OUTDIR%%MEX_NAME%%MEX_EXT%"
set RSP_FILE_INDICATOR=@


rem ********************************************************************
rem Resource compiler parameters
rem ********************************************************************
set RC_COMPILER=rc /fo "%OUTDIR%mexversion.res"
set RC_LINKER=


set POSTLINK_CMDS=del "%LIB_NAME%.x" "%LIB_NAME%.exp"
rem set POSTLINK_CMDS1=mt -outputresource:"%OUTDIR%%MEX_NAME%%MEX_EXT%;2" -manifest "%OUTDIR%%MEX_NAME%%MEX_EXT%.manifest"
set POSTLINK_CMDS1=del "%OUTDIR%%MEX_NAME%%MEX_EXT%.manifest"

set POSTLINK_CMDS2=del "%OUTDIR%%MEX_NAME%%MEX_EXT%.map"



转自:http://blog.csdn.net/viggin/article/details/8761626

你可能感兴趣的:(2012,Visual,Studio,Matlab2012b)