I have a collection of static libraries (.lib) files one of which may have been built with a different version of Visual Studio. This is causing the code generation of a project that links against all of them to fail. Is there any way to determine which version of Visual Studio was used to compile a static library?
相关问题
- How to know full paths to DLL's from .csproj f
- Importing NuGet references through a local project
- Visual Studio 2019 - error MSB8020: The build tool
- 'System.Threading.ThreadAbortException' in
- VS2017 RC - The following error occurred when tryi
相关文章
- How to show location of errors, references to memb
- How to track MongoDB requests from a console appli
- Visual Studio Hangs on Loading UI Library
- How to use Mercurial from Visual Studio 2010?
- Copy different file to output directory for releas
- Edit & Continue doesn't work
- “Csc.exe” exited with code -1073741819
- Visual Studio: Is there an incremental search for
For release libraries, it's unlikely that you could determine the version.
For debug libraries, you can use dumpbin:
The assembly manifest should be at the beginning of the dump and will contain the version of the CRT the library requires along with the full path to the compiler used to build the library.
For executables and DLLs you can get the linker version using dumpbin; it's under "OPTIONAL HEADER VALUES"
Maybe someone else knows of a way to get the version for release libraries; I'm certainly interested too if they are.
If you have the corresponding .PDB files then you can see the version of the compiler from there with a tool like Pdb Inspector.
Or open the PDB in a hex viewer and search for the string "Microsoft (R) Optimizing Compiler". The version will be in four 2-byte hex values just before that string, like in this example:
The version is thus HEX 13 00, 00 00, 6E 5D, 00 00, or 19.0.23918.0.
If the static library was written in C++, and was built with MSVC 2010 or newer version, a FAILIFMISMATCH directive may have been put by compiler into the object files.
I cannot found the official document from Microsoft about the FAILIFMISMATCH directive, but it seems to be used by linker to detect incompatibilities between C++ standard library versions.
You can use the following command to print out those directives from a static library:
(or use the way that mheyman has mentioned if you favor in cygwin or msys)
The result may be similar to this:
Note the first directive: "_MSC_VER=NNNN". In my observation, the NNNN is always match to the compiler version used to create the object file. In my case, the xyz.lib was create with MSVC 2015 update 3, its C++ compiler version is 19.00.24215, so it put /FAILIFMISMATCH:"_MSC_VER=1900" in object file.
A detail mapping between Visual Studio version and Microsoft C/C++ Compiler version can be found at here.
You didn't specify the language, but in C# the answer for knowing the OS and .NET version (in your code at runtime) is:
There would be an equivalent in Managed C++/CLI
That won't tell you the verison of the compiler or of the IDE, but will tell you the verison of the .NET runtimes. You may or may not need to know the OS version.
-Jesse
I've always used something like (in a cygwin window):
The compiler sticks the path of the compiler in the library on debug builds and the Visual Studio's compiler default location is under a path that includes the text 'Visual Studio'.
So, like James McNellis' answer, this also works only for debug builds and is further restricted to builds that actually uses a compiler that sits in a directory with 'Visual Studio #' in the path.
I found this method years ago through a bit of serendipity and it has yet to fail.
This has the benefit that it is easy to remember if you are familiar with Unix command line tools.