Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
520 views
in Technique[技术] by (71.8m points)

visual c++ - 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.
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 FilesMicrosoft Visual Studio 9.0VC>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 FilesMicrosoft Visual Studio 8VC>cl

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

For 2005:

C:Program FilesMicrosoft Visual Studio 8VC>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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...