jan 09 2014

Problems and Solutions: Using Microsoft Visual Studio 2013 in Matlab R2013b to compile .mex files

I found this problem when trying to configure Matlab R2013b to use Microsoft Visual Studio Ultimate 2013 as compiler C / C . O Visual Studio 2013 is not in list compilers supported by Matlab R2013b Windows not 64 bits.

When trying to use the command 'mex -setup’ and try to locate a compiler automatically appear the following error:

>> mex -setup

Welcome to mex -setup. This utility will help you set up
a default compiler. For a list of supported compilers, see
http://www.mathworks.com/support/compilers/R2013b/win64.html

Please choose your compiler for building MEX-files:

Would you like mex to locate installed compilers [and]/n? and

No supported SDK or compiler was found on this computer.
For a list of supported compilers, see
http://www.mathworks.com/support/compilers/R2013b/win64.html

Unable to complete successfully.

I tried to install Microsoft Windows SDK 7.1 (Microsoft Windows SDK for Windows 7 and .NET Framework 4), but it did not work. The compiler still not being found, even trying to manually select the path.

The solution I found was a arquivo no File Exchange do Matlab called Matlab mex support for Visual Studio 2013 (and mbuild). Simply download the file VS2013.zip, and unpack 5 files that are inside it (some with .bat extension and others with .stp extension) in the folders specified by the README.TXT.

The solution was created by the author to Matlab R2013a, but worked perfectly well in MATLAB R2013b, simply take care to replace the string “R2013a” by “R2013b” the indicated paths.

Made unpacking the files in the specified folders, again ran the “mex -setup” and this time it worked, as can be seen below:

>> mex -setup

Welcome to mex -setup. This utility will help you set up
a default compiler. For a list of supported compilers, see
http://www.mathworks.com/support/compilers/R2013b/win64.html

Please choose your compiler for building MEX-files:

Would you like mex to locate installed compilers [and]/n? and

Select a compiler:
[1] Microsoft Visual C 2013 in C:\Program Files (x86)\Microsoft Visual Studio 12.0
[2] Microsoft Visual C 2013 in C:\Program Files (x86)\Microsoft Visual Studio 12.0\

[0] None

Compiler: 2

Please verify your choices:

Compiler: Microsoft Visual C 2013
Location: C:\Program Files (x86)\Microsoft Visual Studio 12.0\

Are these correct [and]/n?

***************************************************************************
Warning: MEX-files generated using Microsoft Visual C 2013 require
that Microsoft Visual Studio 2013 run-time libraries be
available on the computer they are run on.
If you plan to redistribute your MEX-files to other MATLAB
users, be sure that they have the run-time libraries.
***************************************************************************

Trying to update options file: C:\Users(removed)\AppDataRoamingMathWorksMATLABR2013bmexopts.bat
From template: C:\PROGRA~1MATLABR2013bbinwin64mexoptsmsvc120opts.bat

Done . . .

**************************************************************************
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
Building with the -largeArrayDims option enables the new API.
**************************************************************************

Notice that, bisonhamente, Two options appear, one with the path ending with a backslash and one without the bar. Be sure to choose the option with the bar, which in my case is the second, otherwise appear errors at compile time.

Choosing the first option, error in the compilation (rimou! :)):

>> mex yprime.c
LINK : fatal error LNK1561: entry point must be defined

C:\PROGRA~1MATLABR2013BBINMEX.PL: Error: Link of ‘yprime.exe’ failed.

Choosing the second option, works perfectly:

>> mex yprime.c
>> T=1; Y = 1:4;
yprime(T,And)

years =

2.0000 8.9685 4.0000 -1.0947

Compiler running. Para deixar meus códigos mais rápidos agora só me falta aprender a escrever os arquivos .mex 🙂

Permanent link to this article: https://www.skooterblog.com/2014/01/09/problemas-e-solucoes-usando-o-microsoft-visual-studio-2013-no-matlab-r2013b-para-compilar-arquivos-mex/

Leave a comment

2 Comments on "Problems and Solutions: Using Microsoft Visual Studio 2013 in Matlab R2013b to compile .mex files"

Notify about
Avatar
Sort by:   more new | older | top rated
Carolina
Visitor
Carolina

Hello! Is there any option to the R2015a? I'm having the same problem, I've done everything and it didn't work.

wpDiscuz