I have .lib
file compiled from C code. How I know if this self-contained static library or just an import lib and DLL will be needed at runtime? Is there some dumpbin
option I'm missing?
Asked
Active
Viewed 1.7k times
71

zaharpopov
- 16,882
- 23
- 75
- 93
-
Strange question. If you don't have the DLL then you can only cross your fingers. – Hans Passant Jun 19 '11 at 16:25
-
2Normally you would read the documentation. If you don't have documentation and don't know the provenance of the .lib then you should think twice about using it. – David Heffernan Jun 19 '11 at 16:31
-
7Sadly, many libraries come with "getting started" or "readme" files that are out of date, and some mysterious hidden option to configure if it's building static or dynamic. This gets worse when it's not even a library I want, but one needed by a library that I want. – AndrewS Sep 18 '13 at 22:37
2 Answers
89
Use the lib command. If it's static, lib will show you a pile of .obj files inside. Not so if it's an implib.
lib /list foo.lib
will do it.
Also see:
https://learn.microsoft.com/en-us/cpp/build/reference/managing-a-library

0xC0000022L
- 20,597
- 9
- 86
- 152

bmargulies
- 97,814
- 39
- 186
- 310
-
1can you suggest which option(s) to give `lib` to perform this? I can't understand from its doc – zaharpopov Jun 20 '11 at 05:02
-
@zaharpopov MSDN docs have been revamped since the release of Windows 8.1. Please check. – tom_mai78101 Jan 21 '16 at 06:49
-
8There seems to be a similar way. Open the lib file with 7zip. If it's an imort lib, it would contain *.dll files. Otherwise, it would contain *.obj files, maybe in a folder. – sean Jun 08 '17 at 04:51
-
Your answer, in my opinion, is the better one. Thank you, i will adapt to your method. Before, I did it slightly differently: https://stackoverflow.com/questions/8019464/static-library-v-s-import-library-on-windows-platform/51861571#51861571 but your `lib` method is the better method. – daparic Mar 29 '19 at 08:32
-
Trying this today on Windows 10, I got `'lib' is not recognized as an internal or external command, operable program or batch file.` – Zois Tasoulas Jul 28 '21 at 18:18
-
this is bad answer, please also let other know how to install `lib` command, since this command is not default avaible on any platform. – Nicholas Jela Apr 06 '22 at 06:22
-
1Windows is only one platform, and this question is about windows, and the lib command comes with the windows SDK, which you need to have to do any development. – bmargulies Apr 06 '22 at 20:51
-
If you have Visual Studio installed, there is a lib.exe there, as well. If you install the Community edition, 2019, it will be somewhere like "C:\Program Files (x86)\ Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\##.##.#####\bin\Hostx64\x64\". The "##.##.#####" are a bunch of numbers, which I'm not sure what are... maybe a specific version? Plus, if you need the executable for 32 bit windows there are other folders there as well (e.g. Hostx32) – Breno May 04 '22 at 19:19
-
There is _no_ dichotomy between static and import libs. A lib can just as well contain both: code and import descriptors. It's as easy as `lib /out:combined.lib static.lib implib.lib` to create one or reverse the process by doing `lib /remove:implib.dll combined.lib` (assuming `implib.dll` to be the DLL name whose import descriptors we initially merged). Last but not least invoking `lib.exe` == `link.exe /lib`. – 0xC0000022L Jan 20 '23 at 12:32
-
So the claim that an import lib cannot contain object files may technically be true, but if you are looking at a combined lib, you're still none the wiser. – 0xC0000022L Jan 20 '23 at 12:38
4
Look in its accompanying header files ,if the function are 'decorated' with __declspec(dllimport)
that it's an import library. Or look for an accompanying .def file ,that also tells you that it's an import library.
-
1
-
Meanwhile other compiler support this, mostly to stay compatible to some extent with what `cl.exe` does. However, looking into a header file isn't useful advice. It assumes there is a header (in addition to the lib we're looking at), it assumes the header contains these, but those could be hidden behind an API -- which could be as obvious as `DECLSPEC_IMPORT` or as innocuous as `POLARITY` or `FOOBAR_API` or something as counterintuitive as `DLLEXP`. Aside from that no header is needed to create or process import libs. – 0xC0000022L Jan 20 '23 at 12:28