Why winpcap requires both .lib and .dll to run?

2019-07-19 08:02发布

问题:

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?

回答1:

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.



回答2:

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


回答3:

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.



标签: c dll winpcap