Notes on Visual Studio 15
The following notes are based on our experience adding support for the
Visual Studio 15 C/C++ compiler in build2
.
Normally, when it comes to Visual Studio (referred to as VC from now on),
there are three numbers that can be used to identify it: the release year,
the VC version, and the cl.exe
compiler version. For example,
here is the mapping table we keep as a comment in the build2
source code:
// year ver cl.exe crt/dll // // 2015 14 19.00 14.0/140 // 2013 12 18.00 12.0/120 // 2012 11 17.00 11.0/110 // 2010 10 16.00 10.0/100 // 2008 9 15.00 9.0/90 // 2005 8 14.00 8.0/80 // 2003 7.1 13.10 7.1/71
The last column lists the runtime version and its representation in the
DLL name (e.g., msvcp140.dll
). Notice that the runtime versions
match the VC versions (though 13 was conspicuously skipped). The year is
just a marketing gimmick so we ignore in preference to the version, for
example VC14. The compiler version is available as the _MSC_VER
preprocessor macro and you sometimes need to map between the two.
While confusing initially (why three versions?), everyone got used to it. With VC15, however, Microsoft decided to shake things up a bit. Take a look at this path from the RC1 installation, it sets up the expectations nicely:
...\Microsoft Visual Studio\2017\Professional\VC\Redist\MSVC\14.10.24629\x64\Microsoft.VC150.CRT\msvcp140.dll
The year (2017) and the VC version (15) are as expected. But look at the
runtime – it's still 14.0! Or is it? What's that 14.10 earlier in the
path? Checking the msvcp140.dll
's embedded manifest confirms
this – it is 14.10. According to Microsoft it is backwards-compatible
with 14.0 and, presumably, they had to still call the DLLs
*140.dll
to allow upgrading existing programs without a
re-link.
Ok, what about the compiler version?
> cl.exe Microsoft (R) C/C++ Optimizing Compiler Version 19.10.24629 for x64
Another deviation from the established scheme: it's not 20, it's 19.10.
Fun fact: up to Preview 4 the compiler version was 19.00 which means it was
indistinguishable from VC14 via _MSC_VER
. Thankfully, that got
fixed.
Here is the new line for VC15 in our mapping table (VC14 is shown for comparison):
// year ver cl.exe crt/dll // // 2017 15 19.10 14.1/140 // 2015 14 19.00 14.0/140
BTW, if you ever need to determine the runtime version at compile time,
there is the crtversion.h
header. Here are its contents (again
from VC15 RC1):
#define _VC_CRT_MAJOR_VERSION 14 #define _VC_CRT_MINOR_VERSION 10 #define _VC_CRT_BUILD_VERSION 24629 #define _VC_CRT_RBUILD_VERSION 0
Another notable change is the addition of the /std:
compiler
option. Up until now (or, more precisely, up until VC14 Update 3 where this
option was added), C++ standard-wise, you got what you got. Now the default
is c++14
and to enable C++17 (and beyond) one has to pass the
/std:c++latest
. There is also the _MSVC_LANG
macro
that one can use to determine the enabled standard.
The RC1 and RC2 installers only create one Visual Studio Command Prompt shortcut in the Start menu. While one can appreciate the simplification, unfortunately, on 64-bit Windows the shortcut is for the 32-bit environment.
We've reported this and hopefully it will be fixed before the final release. In the meantime (or if this isn't fixed), the good news is that the batch files are still there and we can create the necessary shortcuts ourselves. The batch files are located in this directory:
...\Microsoft Visual Studio\2017\Professional\VC\Auxiliary\Build\
For example, to create a shortcut for the native 64-bit environment,
right-click on vcvars64.bat
and select "Create shortcut". Then
edit the shortcut's "Target" field and add the %comspec% /k
prefix.
Also see the discussion
on r/cpp
.