16

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?

4
  • That information will be supplied with the .lib file Commented Nov 5, 2011 at 10:12
  • If you have no clue like this then you do not want to use the library. Contact the owner of the code and ask about support options. Commented Nov 5, 2011 at 10:13
  • 2
    Note that static library and import library are just two extrema in the spectrum. You can also have a mixed static/import library. Commented Nov 5, 2011 at 13:22
  • Re your second question: do you mean which DLLs are included in the static library, or which DLLs the static library depends on? Commented Nov 5, 2011 at 23:04

2 Answers 2

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.)

Sign up to request clarification or add additional context in comments.

2 Comments

To expand on this: link the static library with a trivial program, and then use Dependency Walker to look for any new DLL dependencies.
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.
6

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.

2 Comments

I have to vow and admit to the more superior answer found here: stackoverflow.com/questions/6402586/…
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).

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.