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

后端 未结 4 2168
轮回少年
轮回少年 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: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 
    /*
     * 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!

提交回复
热议问题