Reputation: 63816
I have some pre-built libraries and work with C++ projects using various VS versions (2015, 2017, 2019).
Is there a way I can inspect a pre-built .lib or .dll file to determine which platform (142,141,140) it was built against?
Upvotes: 3
Views: 1324
Reputation: 17678
The linker timestamp and version are embedded in the PE header and optional header respectively, and can be retrieved with dumpbin
, for example:
C:\>dumpbin /nologo /headers %systemRoot%\system32\cmd.exe
Dump of file C:\WINDOWS\system32\cmd.exe
PE signature found
File Type: EXECUTABLE IMAGE
FILE HEADER VALUES
8664 machine (x64)
7 number of sections
7E28B365 time date stamp <-------
0 file pointer to symbol table
0 number of symbols
F0 size of optional header
22 characteristics
Executable
Application can handle large (>2GB) addresses
OPTIONAL HEADER VALUES
20B magic # (PE32+)
14.20 linker version <-------
31000 size of code
...
The timestamp used to hold the actual date and time the module was built on, but that's no longer the case in Windows 10 for reasons of reproducible builds, as explained in Raymond Chen's Why are the module timestamps in Windows 10 so nonsensical?: "setting the timestamp to be a hash of the resulting binary preserves reproducibility".
The linker version, however, is still reliably filled-in with the actual major.minor
version of the linker used to build the module. This identifies the toolset being used, for example cmd.exe
from Windows 10 version 2004 appears to have been built with VS 2019 v16.0 i.e. toolset v142.
The linker version alone does not guarantee that the entire toolset was used as-is, since it is technically possible to mix tools and libraries between different versions. However, that would be less common, so the linker version gives a strong hint of what versions of the libraries were used.
A mapping between linker versions and VS versions can be found here for example:
MSVC ver _MSC_VER
14.0 1900 (VS 2015 14.0)
14.1 1910 (VS 2017 15.0)
14.11 1911 (VS 2017 15.3)
...
14.16 1916 (VS 2017 15.9)
14.2 1920 (VS 2019 16.0)
14.21 1921 (VS 2019 16.1)
...
14.28 1928 (VS 2019 16.8)
Upvotes: 3