Finding version of Microsoft C++ compiler from command-line (for makefiles)

后端 未结 6 1125
孤城傲影
孤城傲影 2020-12-04 21:00

I must be missing something really obvious, but for some reason, the command-line version of the Microsoft C++ compiler (cl.exe) does not seem to support reporting just its

相关标签:
6条回答
  • 2020-12-04 21:39

    Just run it without options.

    P:\>cl.exe
    Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8168 for 80x86
    Copyright (C) Microsoft Corp 1984-1998. All rights reserved.
    
    usage: cl [ option... ] filename... [ /link linkoption... ]
    
    0 讨论(0)
  • 2020-12-04 21:40

    Create a .c file containing just the line:

    _MSC_VER
    

    or

    CompilerVersion=_MSC_VER
    

    then pre-process with

    cl /nologo /EP <filename>.c
    

    It is easy to parse the output.

    0 讨论(0)
  • 2020-12-04 21:41

    Are you sure you can't just run cl.exe without any input for it to report its version?

    I've just tested running cl.exe in the command prompt for VS 2008, 2005, and .NET 2003 and they all reported its version.

    For 2008:

    d:\Program Files\Microsoft Visual Studio 9.0\VC>cl

    Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.30729.01 for 80x86

    For 2005, SP 1 (added Safe Standard C++ classes):

    C:\Program Files\Microsoft Visual Studio 8\VC>cl

    Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.762 for 80x86

    For 2005:

    C:\Program Files\Microsoft Visual Studio 8\VC>cl

    Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.42 for 80x86

    For .NET 2003:

    Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 13.10.6030 for 80x86

    EDIT

    For 2010, it will be along the line of:

    Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.XX.YYYYY.ZZ for 80x86

    or depending on targeted platform

    Microsoft (R) C/C++ Optimizing Compiler Version 16.XX.YYYYY.ZZ for x64

    For 2012:

    Microsoft (R) C/C++ Optimizing Compiler Version 17.XX.YYYYY.ZZ for $$$

    where $$$ is the targeted platform (e.g. x86, x64, ARM), and XX, YYYYY, and ZZ are minor version numbers.

    For 2013:

    Microsoft (R) C/C++ Optimizing Compiler Version 18.XX.YYYYY.ZZ for $$$

    where $$$ is the targeted platform (e.g. x86, x64, ARM), and XX, YYYYY, and ZZ are minor version numbers.

    For 2015:

    Microsoft (R) C/C++ Optimizing Compiler Version 19.XX.YYYYY for $$$

    where $$$ is the targeted platform (e.g. x86, x64, ARM), and XX and YYYYY are minor version numbers.

    0 讨论(0)
  • 2020-12-04 21:44

    Try:

    cl /v
    

    Actually, any time I give cl an argument, it prints out the version number on the first line.

    You could just feed it a garbage argument and then parse the first line of the output, which contains the verison number.

    0 讨论(0)
  • 2020-12-04 21:46

    I had the same problem today. I needed to set a flag in a nmake Makefile if the cl compiler version is 15. Here is the hack I came up with:

    !IF ([cl /? 2>&1 | findstr /C:"Version 15" > nul] == 0)
    FLAG = "cl version 15"
    !ENDIF
    

    Note that cl /? prints the version information to the standard error stream and the help text to the standard output. To be able to check the version with the findstr command one must first redirect stderr to stdout using 2>&1.

    The above idea can be used to write a Windows batch file that checks if the cl compiler version is <= a given number. Here is the code of cl_version_LE.bat:

    @echo off
    FOR /L %%G IN (10,1,%1) DO cl /? 2>&1 | findstr /C:"Version %%G" > nul && goto FOUND
    EXIT /B 0
    :FOUND
    EXIT /B 1
    

    Now if you want to set a flag in your nmake Makefile if the cl version <= 15, you can use:

    !IF [cl_version_LE.bat 15]
    FLAG = "cl version <= 15"
    !ENDIF
    
    0 讨论(0)
  • 2020-12-04 22:00

    Have a look at C++11 Features (Modern C++)

    and section "Quick Reference Guide to Visual C++ Version Numbers" ...

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