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 version when run. We need this to write makefiles that check the compiler version a user of our tool has installed (they get makefiles with code they are to compile themselves locally, so we have no control over their compiler version).
In gcc, you just give the option -v or --version to get a nice version string printed.
In cl.exe, you get an error for -v.
I have read the MSDN docs and compiler online help, and I cannot find the switch to just print the compiler version. Annoyingly, you always get the version when the compiler starts... but you seem not to be able to start the compiler just to get the version out of it.
Finding compiler vendor / version using qmake seemed similar, but only deals with the simple case of gcc.
I am trying this with VC++ Express 2005, if that matters. I hoped it would not, as detecting the compiler version is best done in a compiler-version-independent way :)
Update, after replies:
Type “gcc –version” in command prompt to check whether C compiler is installed in your machine.
You can test that you have the C++ compiler, cl.exe , installed correctly by typing 'cl' and you should see a copyright message with the version and basic usage description.
In Visual StudioIn the left pane, select Configuration Properties, C/C++ and then choose the compiler option category. The topic for each compiler option describes how it can be set and where it is found in the development environment. For more information and a complete list of options, see MSVC compiler options.
More precisely, the default path where you'll find the compiler is C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin . The compiler is cl.exe .
Is there any command to get the C# compiler version? The csc command seams has no option to show compiler version. P.S when I enter csc command in Developer Command Prompt For VS2015 it returns: Microsoft (R) Visual C# Compiler version 1.3.1.60616 Copyright (C) Microsoft Corporation. All rights reserved.
You can build C and C++ applications on the command line by using tools that are included in Visual Studio. The Microsoft C++ (MSVC) compiler toolset is also downloadable as a standalone package from the Visual Studio downloads page. It's part of the Build Tools for Visual Studio package.
To compile your program, enter cl hello.c at the developer command prompt. You can see the executable program name, hello.exe, in the lines of output information that the compiler displays: c:\hello>cl hello.c Microsoft (R) C/C++ Optimizing Compiler Version 19.10.25017 for x86 Copyright (C) Microsoft Corporation.
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:
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With