2
votes

The Visual Studio 2012 Compiler November 2012 CTP (VS2012+) gives access to new C++11 features. I would like to build mex files from Matlab 2013a using VS2012+; Matlab 2013a supports the ordinary VS2012. Is it possible to make Matlab 2013a build with VS2012+?

Visual Studio 2012 Compiler November 2012 CTP: http://www.microsoft.com/en-us/download/details.aspx?id=35515

Additional information: In Visual Studio 2012, the compiler update is activated by going into project settings, and then choosing the platform toolset as "Microsoft Visual C++ Compiler Nov 2012 CTP (v120_CTP_Nov2012)". The default platform toolset is "Visual Studio 2012 (v110)". I would have expected to see this reflected in the compiler or linker switches, but I am unable to spot any differences. To key issue is then how to inform Visual Studio 2012 to do the same from the command line.

1
Have you tried selecting the new compiler with mex -setup? If so, what happens? - nhowe
You get to select between Visual Studio 2012 and Visual Studio 2010. - kaba
I would assume that the VS2012+ compiler would replace the previous VS2012 compiler. Have you tried selecting it and compiling something that relies on the new features, to see if it works? That sort of information would be useful to include in your question. - nhowe
VS2012 has support for multiple platform toolsets, and therefore can have multiple versions of the compiler present; the compiler is not replaced. I added information about this. - kaba

1 Answers

2
votes

The Visual Studio 2012 Compiler Nov 2012 CTP is a separate executable, which is located at

C:\Program Files (x86)\Microsoft Visual C++ Compiler Nov 2012 CTP

The bin-subdirectory contains the cl.exe, which is the new compiler. A file with the same name exists at the Visual Studio 2012 installation directory. To make Matlab refer to the updated compiler, open (in a plain-text editor) the file

C:\Program Files\MATLAB\R2013a\bin\win64\mexopts\msvc110opts.bat

and add the following just before the compiler parameters:

rem Override the compiler selection.
set COMPILERUPDATEDIR=C:\Program Files (x86)\Microsoft Visual C++ Compiler Nov 2012 CTP
set PATH=%COMPILERUPDATEDIR%\bin\amd64;%COMPILERUPDATEDIR%\bin;%PATH%

This works since the cl.exe is searched from left to right in the PATH variable.

Local vs global options files

Note that the options-files in the mexopts directory are not directly used by Matlab; instead, they are taken local copies, and these are then used as the actual options files. When running

mex -setup

Matlab takes a local copy of the global options file, and places it in a directory which can be obtained by running mex with the -v option. This is the default options file. Therefore, if you are using the default options file, then you need to run mex -setup to see the changes.

Alternatively, you may want to take a local copy of the global options file yourself, and then specify the options file by the -f option in mex. This way you don't need to modify the official options files.