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

后端 未结 4 2091
轮回少年
轮回少年 2021-02-07 12:44

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 wonderin

相关标签:
4条回答
  • 2021-02-07 13:09

    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.

    0 讨论(0)
  • 2021-02-07 13:22

    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

    0 讨论(0)
  • 2021-02-07 13:24

    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
    
    0 讨论(0)
  • 2021-02-07 13:36

    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!

    0 讨论(0)
提交回复
热议问题