Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Detect if I'm Compiling Code with a particular Visual Studio version?

Is there any way to know if I'm compiling under a specific Microsoft Visual Studio version?

like image 935
Vhaerun Avatar asked Sep 16 '08 07:09

Vhaerun


People also ask

How do I know which compiler I am using in Visual Studio code?

To open the Developer Command Prompt for VS, start typing 'developer' in the Windows Start menu, and you should see it appear in the list of suggestions. The exact name depends on which version of Visual Studio or the Visual Studio Build Tools you have installed. Select the item to open the prompt.

How do I know which Visual Studio I have?

On macOS, go to Code > About Visual Studio Code. On Windows and Linux, go to Help > About. The VS Code version is the first Version number listed and has the version format 'major.

What does Visual Studio compile with?

1.3 CMake. CMake is used for generating the Visual Studio solution and project files needed for building MuseScore. If you're building a standard build, Visual Studio will automatically use its own internal copy of CMake, so you don't need to download it separately.

Does Visual Studio code have its own compiler?

No, it does not come with its own VS compiler, except for (apparently) "ASP.NET, Node. js, or TypeScript". But it is the first cross-platform development tool in the Visual Studio family, for a certain definition of the phrase "development tool".


2 Answers

_MSC_VER and possibly _MSC_FULL_VER is what you need. You can also examine visualc.hpp in any recent boost install for some usage examples.

Some values for the more recent versions of the compiler are:

MSVC++ 14.24 _MSC_VER == 1924 (Visual Studio 2019 version 16.4) MSVC++ 14.23 _MSC_VER == 1923 (Visual Studio 2019 version 16.3) MSVC++ 14.22 _MSC_VER == 1922 (Visual Studio 2019 version 16.2) MSVC++ 14.21 _MSC_VER == 1921 (Visual Studio 2019 version 16.1) MSVC++ 14.2  _MSC_VER == 1920 (Visual Studio 2019 version 16.0) MSVC++ 14.16 _MSC_VER == 1916 (Visual Studio 2017 version 15.9) MSVC++ 14.15 _MSC_VER == 1915 (Visual Studio 2017 version 15.8) MSVC++ 14.14 _MSC_VER == 1914 (Visual Studio 2017 version 15.7) MSVC++ 14.13 _MSC_VER == 1913 (Visual Studio 2017 version 15.6) MSVC++ 14.12 _MSC_VER == 1912 (Visual Studio 2017 version 15.5) MSVC++ 14.11 _MSC_VER == 1911 (Visual Studio 2017 version 15.3) MSVC++ 14.1  _MSC_VER == 1910 (Visual Studio 2017 version 15.0) MSVC++ 14.0  _MSC_VER == 1900 (Visual Studio 2015 version 14.0) MSVC++ 12.0  _MSC_VER == 1800 (Visual Studio 2013 version 12.0) MSVC++ 11.0  _MSC_VER == 1700 (Visual Studio 2012 version 11.0) MSVC++ 10.0  _MSC_VER == 1600 (Visual Studio 2010 version 10.0) MSVC++ 9.0   _MSC_FULL_VER == 150030729 (Visual Studio 2008, SP1) MSVC++ 9.0   _MSC_VER == 1500 (Visual Studio 2008 version 9.0) MSVC++ 8.0   _MSC_VER == 1400 (Visual Studio 2005 version 8.0) MSVC++ 7.1   _MSC_VER == 1310 (Visual Studio .NET 2003 version 7.1) MSVC++ 7.0   _MSC_VER == 1300 (Visual Studio .NET 2002 version 7.0) MSVC++ 6.0   _MSC_VER == 1200 (Visual Studio 6.0 version 6.0) MSVC++ 5.0   _MSC_VER == 1100 (Visual Studio 97 version 5.0) 

The version number above of course refers to the major version of your Visual studio you see in the about box, not to the year in the name. A thorough list can be found here. Starting recently, Visual Studio will start updating its ranges monotonically, meaning you should check ranges, rather than exact compiler values.

cl.exe /? will give a hint of the used version, e.g.:

c:\program files (x86)\microsoft visual studio 11.0\vc\bin>cl /? Microsoft (R) C/C++ Optimizing Compiler Version 17.00.50727.1 for x86 ..... 
like image 84
23 revs, 18 users 26% Avatar answered Sep 29 '22 00:09

23 revs, 18 users 26%


Yep _MSC_VER is the macro that'll get you the compiler version. The last number of releases of Visual C++ have been of the form <compiler-major-version>.00.<build-number>, where 00 is the minor number. So _MSC_VER will evaluate to <major-version><minor-version>.

You can use code like this:

#if (_MSC_VER == 1500)    // ... Do VC9/Visual Studio 2008 specific stuff #elif (_MSC_VER == 1600)    // ... Do VC10/Visual Studio 2010 specific stuff #elif (_MSC_VER == 1700)    // ... Do VC11/Visual Studio 2012 specific stuff #endif 

It appears updates between successive releases of the compiler, have not modified the compiler-minor-version, so the following code is not required:

#if (_MSC_VER >= 1500 && _MSC_VER <= 1600)    // ... Do VC9/Visual Studio 2008 specific stuff #endif 

Access to more detailed versioning information (such as compiler build number) can be found using other builtin pre-processor variables here.

like image 32
display101 Avatar answered Sep 28 '22 23:09

display101