Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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:

  • Running cl.exe without any arguments prints its version and some help text.
  • This looks like the most portable way to get at the version, across vc versions.
  • You then have to parse a multi-line output, but that is not too difficult.
  • We did this in the end, and it works.
like image 705
jakobengblom2 Avatar asked Aug 05 '09 13:08

jakobengblom2


People also ask

How do I know what version of c compiler I have?

Type “gcc –version” in command prompt to check whether C compiler is installed in your machine.

How do I know if Visual Studio C++ compiler is installed?

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.

How do I find the compiler in Visual Studio?

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.

Where is Visual Studio compiler located?

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?

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.

How do I build C and C++ applications on the command line?

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.

How do I compile a program in C++?

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.

How to check the version of a compiler using findstr command?

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:


2 Answers

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.

like image 108
KTC Avatar answered Oct 02 '22 22:10

KTC


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 
like image 27
Linoliumz Avatar answered Oct 02 '22 21:10

Linoliumz