Skip to content
⌘ NSIS Forum Archive

How to detect C++ compiler version?

3 posts

postb99#

How to detect C++ compiler version?

Hello,

I'm about to write my first installer.

The C++ application it will install requires a specific compiler version.

So I thought I could do this:
  • provide a variable in a text file for major version number, example "1000". This will be filled by people which packages a specific version of app compiled with a specific compiler.
  • read "__MSC_VER"
  • compare both
  • for some versions, perform other checks, typically 10.00 version requires Windows SDK 7.1 etc


What do I write in a NSIS script to perform the equivalent of the following and equivalent?
#if(defined(__MSC_VER))
Thanks
Anders#
Originally Posted by postb99 View Post
The C++ application it will install requires a specific compiler version.
What do you mean by this? The CRT runtime? Or are you actually going to compile something on the end-users machine?
LoRd_MuldeR#
_MSC_VER is a pre-processor macro. It will expand when you compile your program. And it will expand to whatever version of MSVC you have been using to compile the program. Consequently, reading this value at runtime, on a user's machine, will tell you absolutely nothing about what compiler (or C++ Runtime) is installed there! It is simply a constant value in your compiled program.

But why do you want to detect the compiler version on the user's machine? Users usually do not have a compiler installed at all! So maybe what you actually want is to detect which version of the C++ Runtime libraries is installed? Or are you shipping source files to be compiled on the user's machine? If so, it would be very unusual and you should be shipping the compiled program ("EXE file") instead.

In case you really which to detect the compiler version, e.g. because you are distributing a piece of software that is intended to be used by software developers, just run the cl.exe that is installed on the user's machine. Then parse the version string...

D:\Microsoft Visual Studio 11.0\VC>cl.exe
Microsoft (R) C/C++ Optimizing Compiler Version 17.00.61030 for x64
Copyright (C) Microsoft Corporation. All rights reserved.
Either that, or read the installed Visual Studio version from the registry 😉