views:

93

answers:

3

Specifications can be seen here:

http://www.winpcap.org/docs/docs_40_2/html/group__wpcapsamps.html

It's very strange,either .lib or .dll is enough IMO,why does it require both?

A: 

If you are calling a Dll you will need an Lib with that. you can see the below link for more info

This is from wikipedia

Linking to dynamic libraries is usually handled by linking to an import library (your .LIB) when building or linking to create an executable file. The created executable then contains an import address table (IAT) by which all DLL function calls are referenced (each referenced DLL function contains its own entry in the IAT). At run-time, the IAT is filled with appropriate addresses that point directly to a function in the separately-loaded DLL.

SysAdmin
It seems that `.lib` resembles '.h' files here.
Gtker
@Gtker - .lib does'nt resemble a .H file. when building a exe which access dll there are 2 option (i) get the .h, .lib (for compiling and linking) and .dll(for runtime) ready. (ii) use Loadlibrary(), GetProcAddress() and call your dll functions. in this case you wont need .Lib or .H files. (my advice is to stay away from the second choice)
SysAdmin
+1  A: 

In general, you need the .lib for the linker, and .dll at runtime. The .lib file is called an "import library", which contains the glue that tells the linker the functions you're calling can be found in the associated .dll file.

You will probably find that only the .dll file is required at runtime.

This is a widely used layout for Win32 DLL projects and is not limited to Winpcap.

Greg Hewgill
But most of the time, I only need either `.lib` or `.dll`,but not both.
Gtker
@Gtker: I'm not sure I understand your concern about using both files. The instructions on that documentation page you referenced look perfectly normal to me.
Greg Hewgill
When does a `.dll` need an "import library"? Many programes that uses MSVCR.dll never requires such an "import library".
Gtker
@Gtker: That library is a special case because the compiler already knows about it. However, consider that you must include `user32.lib` in your build in order to link to `user32.dll`. Or, for a more relevant example, that very page you quoted mentions using `ws2_32.lib` which is required to link to `ws2_32.dll` at runtime.
Greg Hewgill
+1  A: 

Its not only with winpcap, all external libraries are like that.

  • When you compiles your source codes which using particular library, you need header files *.h from that library, and you will get *.o files
  • When you link those *.o files to executables, you will need *.lib or *.dll.a files.
  • When you run those executable files, you will need *.dll files
S.Mark
I understand the `.lib` or `.dll` case,but not `.lib` **AND** `.dll`
Gtker
@Gtker, you mean when you run (not compiling) your executables, you need .lib?
S.Mark
I don't understand what's a "import library", I've only used "object library" so far.
Gtker
@Gtker: That's the source of your misunderstanding then. An "import library" contains no actual compiled code (unlike an object library). An import library only contains instructions to the linker to set up dynamic binding to the associated `.dll`. Both object libraries and import libraries have the same file extension `.lib`.
Greg Hewgill