74

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?

3
  • Strange question. If you don't have the DLL then you can only cross your fingers. Commented Jun 19, 2011 at 16:25
  • 2
    Normally 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. Commented Jun 19, 2011 at 16:31
  • 7
    Sadly, 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
    Commented Sep 18, 2013 at 22:37

2 Answers 2

95

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

10
  • 1
    can you suggest which option(s) to give lib to perform this? I can't understand from its doc
    – zaharpopov
    Commented Jun 20, 2011 at 5:02
  • @zaharpopov MSDN docs have been revamped since the release of Windows 8.1. Please check. Commented Jan 21, 2016 at 6:49
  • 8
    There 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
    Commented Jun 8, 2017 at 4:51
  • Your answer, in my opinion, is the better one. Thank you, i will adapt to your method. Before, I did it slightly differently: stackoverflow.com/questions/8019464/… but your lib method is the better method.
    – daparic
    Commented Mar 29, 2019 at 8:32
  • 1
    Windows 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
    Commented Apr 6, 2022 at 20:51
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.

2
  • 1
    __declspec(dllimport) is a thing of Microsoft compiler only afaik.
    – KcFnMi
    Commented Apr 7, 2022 at 6:01
  • 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. Commented Jan 20, 2023 at 12:28

Not the answer you're looking for? Browse other questions tagged or ask your own question.