Check MSVC Compiler Version on Windows

Check MSVC Compiler Version on Windows

When working with the Microsoft Visual C++ (MSVC) compiler, it can be useful to know its version. Certain features, optimizations, or library compatibility may depend on the compiler version. This tutorial demonstrates how to check MSVC compiler version on Windows.

First, open the Developer Command Prompt for Visual Studio, which has all MSVC paths preconfigured.

The MSVC compiler version can actually be displayed simply by running cl without any arguments. This prints general information about the compiler, including the version. However, the output contains multiple lines, and some lines appears on the standard error stream rather than the standard output. To filter it, we can redirect standard error to standard output using 2>&1 and then search for the line containing the word Version:

cl 2>&1 | findstr "Version"

Example output:

Microsoft (R) C/C++ Optimizing Compiler Version 19.40.33817 for x64

Sometimes, you only want the numeric version for scripting or logging purposes. You can extract just the version number using the for /F command in combination with findstr:

cl 2>&1 | findstr "Version" | for /F "tokens=7" %i in ('more') do @echo %i

The output will be:

19.40.33817

Important note:

  • The "tokens=7" part works because the version number is the 7th token in the cl output.
  • Depending on the MSVC version, language settings, or regional Windows configuration, the version number might appear in a different position. You may need to adjust the token number to correctly capture it.

Leave a Comment

Cancel reply

Your email address will not be published.