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?
-
Strange question. If you don't have the DLL then you can only cross your fingers.– Hans PassantCommented Jun 19, 2011 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 HeffernanCommented Jun 19, 2011 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.– AndrewSCommented Sep 18, 2013 at 22:37
Add a comment
|
2 Answers
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
-
1can you suggest which option(s) to give
lib
to perform this? I can't understand from its doc 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
-
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.– seanCommented 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.– daparicCommented Mar 29, 2019 at 8:32 -
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. Commented Apr 6, 2022 at 20:51
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
__declspec(dllimport)
is a thing of Microsoft compiler only afaik.– KcFnMiCommented 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 asDECLSPEC_IMPORT
or as innocuous asPOLARITY
orFOOBAR_API
or something as counterintuitive asDLLEXP
. Aside from that no header is needed to create or process import libs. Commented Jan 20, 2023 at 12:28