Here is the note for how I configured Matlab to build mex C/C++ extensions on 64-bit Windows 8:
At first, mex
failed to find a compiler:
>> mex -setup
Please choose your compiler for building external interface (MEX) files:
Would you like mex to locate installed compilers [y]/n? y
Select a compiler:
[0] None
And there existed no mexopts.bat
in %USERPROFILE%\AppData\Roaming\MathWorks\MATLAB\R2010b
.
According to some posts (this one for example) on Matlab Answers,
I had to install Microsoft SDK 7.1.
Surprisingly, when I checked the path it seemed SDK 7.1 had already been installed:
C:\Program Files (x86)\Microsoft SDKs\Windows>dir /B
v7.0A
v7.1A
v8.0
v8.0A
v8.1
v8.1A
[Solution]
Take the following steps:
-
Manually copy
%MATLAB%\R2010b\bin\win64\mexopts\msvc100opts.bat
to%USERPROFILE%\AppData\Roaming\MathWorks\MATLAB\R2010b\mexopts.bat
; -
Since the long path with space
C:\Program Files\...
is annoying, make a new folder namedD:\!\Path
and add it to the%PATH%
environment variable; -
Now create a soft link in command window (admin):
mklink /D VC11 "D:\Program Files (x86)\Microsoft Visual Studio 11.0"
-
Edit
mexopts.bat
-- add/update the following 3 lines:set VSINSTALLDIR=D:\!\Path\VC11 set LINKERDIR='.registry_lookup("SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.1A" , "InstallationFolder").' set PATH=%VSINSTALLDIR%\VC\bin\x86_amd64;%PATH%;
-
Run
mex -v somecode.cpp
andsomecode.mexw64
will be built.
Attached is the mexopts.bat
file. Just copy it to the directory and it might work.