13

How could I tell one .lib file is a static library vs. an import library for a DLL file? Is there a tool or command that could do this?

The second question is: How could I check the dependencies of a static library? I mean, how could I know which DLL files are included in this static library?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
cobe24
  • 221
  • 3
  • 8

2 Answers2

7

An import library will add a DLL dependency to your program. Your program won't start, if you don't have the DLL. (You may use Dependency Walker to get the names of the DLL's of your program depend on.)

As far as I know, static libraries do not have dependencies. They are linked into the program, and only linker errors will tell you if that particular library depends on another library. (At least in GCC; I don't know want is the behaviors of the MS tools.)

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Calmarius
  • 18,570
  • 18
  • 110
  • 157
  • To expand on this: link the static library with a trivial program, and then use Dependency Walker to look for any new DLL dependencies. – Harry Johnston Nov 05 '11 at 22:58
  • 4
    static libraries do typically have DLL dependencies for at least the basic system libraries (ntdll.dll, etc.) and may also have dependencies for the language runtime, e.g., msvcrt.dll. – Harry Johnston Nov 05 '11 at 23:02
5

Given only a wtf.lib file, the question is to determine whether this library file is a static library or an import library. The current way I do this is (via a combination of DOS prompt and a Cygwin Bash shell).

In a DOS prompt, this is needed to correctly run dumpbin.exe:

dumpbin -all wtf.lib > wtf.lib.txt

Then, in the Cygwin shell:

grep 'Archive member name' wtf.lib.txt

If the output of grep spits out a DLL filename, then wtf.lib is an import library. Else, it is a stand-alone static library.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
daparic
  • 3,794
  • 2
  • 36
  • 38
  • 1
    I have to vow and admit to the more superior answer found here: https://stackoverflow.com/questions/6402586/know-if-lib-is-static-or-import – daparic Mar 29 '19 at 08:33
  • Unfortunately this answer completely neglects the possibility of bundling/combining static and import libs into a single `.lib` file. Instead you proclaim a dichotomy that doesn't exist. It shouldn't be a surprise that this is possible and I have seen at least one vendor supplying such a `.lib`. You can create them yourself with `lib /out:combined.lib staticlib.lib implib.lib` and you can also take them apart again with `lib /remove:implib.dll combined.lib` (note that we have to give the DLL name for the `/remove` argument). – 0xC0000022L Jan 20 '23 at 12:18