Visual Studio: how to check used C++ platform toolset programmatically

11,934

Solution 1

The macro _MSC_FULL_VER is different for each platform toolset; and version of Visual Studio. For the (current) Visual Studio 2013 preview, it is 180020617. For Visual Studio 2012 with the November 2012 Compiler CTP (which gave some C++11), it was 170060315. Like _MSC_VER, the first 4 digits are the same for each version of Visual Studio; for Visual Studio 2012 they are always 1700. Here's an example:

#ifdef _MSC_FULL_VER
  #if   _MSC_FULL_VER == 170060315
  // MSVS 2012; Platform Toolset v110
  #elif _MSC_FULL_VER == 170051025
  // MSVS 2012; Platform Toolset v120_CTP_Nov2012
  #elif _MSC_FULL_VER == 180020617
  // MSVS 2013; Platform Toolset v120
  #endif
#endif // _MSC_FULL_VER

Solution 2

I encountered the same problem and added my own preprocessor definition for _MSC_PLATFORM_TOOLSET.
In the project properties in

  • C/C++
  • Preprocessor
  • Preprocessor Definitions

add _MSC_PLATFORM_TOOLSET=$(PlatformToolsetVersion) to make Visual Studio integrate the current Toolset's version to the preprocessor so that your query

#if (_MSC_PLATFORM_TOOLSET > 100)
...
#endif

will finally work.

Solution 3

There are two version numbers that I actually need to know when developing C or C++ with Visual Studio. These are the Visual Studio major version number, and the "cl" compiler major/minor version.

The Visual Studio version number is displayed in the "About" dialog. For instance, for VS2012 I see "Version 11.0.60610.01", so the major version number is "11".

Build tools like bakefile or CMake will create solution files targeted at a Visual Studio major version.

The compiler "major/minor" version is the value of the _MSC_VER macro. Here's a little program that will display this:

#include <stdio.h>
/*
 * Compile and run this on a Visual Studio platform to get
 * the version identifier.
 */
#define PRINT_INT_MACRO(m) (printf("%s: \"%d\"\n", #m, m))

int
main() {
    PRINT_INT_MACRO(_MSC_VER);
      return 0;
}

As the comment says, you have to actually compile it with compiler you want to test. To save you the bother, here is a little table:

Name    Version  _MSC_VER
VS 6        6.0      1200
VS 2002     7.0      1300
VS 2003     7.1      1310
VS 2005     8.0      1400
VS 2008     9.0      1500
VS 2010    10.0      1600
VS 2012    11.0      1700
VS 2013    12.0      1800
VS 2015    13.0      1900

Hope this helps!

Solution 4

I don't know if they've fixed it in VS2015, but it certainly works as expected there.

I created the following small program:

#include <iostream>
using namespace std;

int main()
{
    cout << "_MSC_VER: " << _MSC_VER << endl;
    cout << "_MSC_FULL_VER: " << _MSC_FULL_VER << endl;
    cout << "_MSC_BUILD: " << _MSC_BUILD << endl;

    (void) getchar();

    return 0;
}

I added build configurations for each platform version from VS2010 to VS2015, and the _MSC_VER corresponded to the PLATFORM version as above - despite always building it in Visual Studio 2015 in a VS2015 project.

Cheers,

Ian

Share:
11,934
Serhii
Author by

Serhii

Game developer.

Updated on June 05, 2022

Comments

  • Serhii
    Serhii almost 2 years

    I have to build project using MSVC2012 and v100 platform toolset (from MSVC2010). Unfortunately I'm using C++11 feature "range based for" across the code. I wondering if there is a preprocessor directive that allows to know current platform toolset in compile time. I.e

    #if (_MSC_PLATFORM_TOOLSET > 100)
    #   define ALLOW_RANGE_BASED_FOR 1
    #else
    #   define ALLOW_RANGE_BASED_FOR 0
    #endif
    

    I tried use _MSC_VER macro, but for both platform toolsets it is set to 1700 (and this does make sense, because I'm still using MSVC2012). I'd appreciate any suggestion. Thank you.

  • rustyx
    rustyx over 8 years
    No it doesn't. _MSC_VER is the version of the IDE, not the version of the target platform toolset. You can compile e.g. in VS 2015 with a 2010 compiler by specifying "Platform Toolset = v100"
  • Thorsten S.
    Thorsten S. about 8 years
    +10. This is the only correct version if you need to support different platform toolsets, e.g. if a typedef is defined in 100, but not in 90.
  • jstine
    jstine almost 7 years
    Note: VS2015 is actually 14.0 ... 13.0 was skipped.