File Exchange

image thumbnail

Fixed MATLAB 2016a msvc2013 mexopt files

version (4.38 KB) by Rochus Keller
The original files are full of bugs; with the submitted ones mex starts at least


Updated 30 May 2016

View License

I'm a C++ guy and new to Matlab (though I'm very familiar with R and similar tools). Some of my friends wanted to do analysis of NMR spectra using Matlab, so I downloaded the demo and tried to create a mex which can access my NMR spectrum library ( Surprisingly the mex command didn't find any of the installed compilers. The solutions available to this problem from matlabcentral didn't work because they seem to have changed the mexopt concept with release 2016. So I had to do an analysis myself and was surprised to find out, that the xml config files in the mexopt directory were full of bugs. These mex tries to identify the available compilers using the wrong assumptions in these files. For example: the MSVC 2013 compiler lives in VCROOT\Bin\x86_amd64, not in VCROOT\Bin\amd64; the IDE is called VSWinExpress.exe, not devenv.exe; also MSVC 2013 no longer supports /MT, so I changed to /MD. After these changes mex found at least this compiler but still wasn't able to successfully build. The Matlab terminal only says "Error using mex"; not very helpful. At least it lists the command sent to the compiler when using -v. Here is the result when I directly run it in the terminal:
...MATLAB>cl /c /Zp8 /GR /W3 /EHs /nologo /MD /O2 /Oy- /DNDEBUG /DMX_COMPAT_32 /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /D_SECURE_SCL=0 /DMATLAB_MEX_FILE -I"C:\Program Files\MATLAB\R2016a\extern\include" -I"C:\Program Files\MATLAB\R2016a\simulink\include" C:\Users\me\Documents\MATLAB\yprime.c /FoC:\Users\me\AppData\Local\Temp\mex_81214722198338_2060\yprime.obj
C:\Users\me\Documents\MATLAB\yprime.c : fatal error C1083: Cannot open compiler generated file: 'C:\Users\me\AppData\Local\Temp\mex_81214722198338_2060\yprime.obj': No such file or directory

I will continue my research. Maybe someone has a hint on how to circumvent also this obstacle.


Cite As

Rochus Keller (2021). Fixed MATLAB 2016a msvc2013 mexopt files (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (3)

zhang zhang

I have fixed the problem . for matlab R2016a ,
1. locate envVarExists at msvc2013.xml(at bin\win64\mexopts).
envVarExists name="VS120COMNTOOLS"
2. set VS120COMNTOOLS as system parameter, point to the visual studio install address Common7\Tools .
3. restart matlab
4. mex -setup can see the visual studio

Rochus Keller

Maybe you still have an elder Matlab version which obviously had another concept of finding compilers. On my test machine I had a couple of different ones, even the explicitly recommended 4.9.2 MinGW which created other environment variables than expected by the xml.The IDE of the VC express edition has another name, but everythin else works the same. Anyway it still doesn't compile and I read some other posts whrere people seem to have similar issues.


Are you sure you run a supported version of compiler? For example, Visual Studio 2013 Professional, not Express? See

Works out of the box for me with MSVC 2013 Professional and Community editions.

MATLAB Release Compatibility
Created with R2016a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Tags Add Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!