0

i want to read from a pcap file and used the winpcap libary ( http://www.winpcap.org/ ) for that. after downloading i installed it (and therefore i think their dlls got copied somewhere my system is searching for them). i want to STATIC link the libary to my project, because i dont want to add the winpcap dlls everytime on another computer(which wouldnt be a problem if the computer had installed winpcap too i guess).

in visual studio i added the include path for the headerfiles and the libary path. then i add the libarys "libwpcap.a" and "libpacket.a" to the additional dependencies. (there are also the files "wpcap.lib" and "packet.lib" in the directory, i think they are used for dynamic linking?). my code works fine but when i moved the executeable to my other computer, where i didnt installed winpcap before, it says missing wpcap.dll.. so its just dynamic linked, am i right?

but this case i wanted to prevent. so how can i tell the linker, that he has to link it static.. damn i am searching for it quite some time now. but i dont know what i am doing wrong :( thought .a files get static linked and .lib files are used to link dynamicly.

phön
  • 1,215
  • 8
  • 20

1 Answers1

7

Let's separate between three modes when linking on Windows using VS:

  1. "Full" Static Linkage - a .lib file which is completely embedded in the final image (executable). No other files will be needed.
  2. "Pure" Dynamic Linkage - no linkage is done when building. When you do this, you need at runtime to manually load the .dll file (dynamic library) using e.g. LoadLibrary(), and then to manually request the address of the function you want to call using e.g. GetProcAddress().
  3. "Mixture" mode, which means that you do link against a 'stub' .lib file which does not contain the implementations of the functions, but automatically causes the loader of your executable to load the relevant DLLs and get the addresses of all used functions ("Import table").

The .lib files of modes #1 and #3 are different. Which file is created depends on the settings the creator of the library built her project with: If its "Static Library", a full-implementation .lib file will be created. If it's "Dynamic Library", a stub .lib file and a .dll file will be created. If you use a stub .lib file, your executable will need the .dll file available at runtime.

To solve your problem: If the full-implementation .lib file is not available in the distribution you downloaded, you can download the full WinPCap source code (available from their website) and build it yourself as a static library.

Note, however, that the license might not allow you to do that. I have no idea - you should check this on your own.

Also see:

Community
  • 1
  • 1
Asaf
  • 4,317
  • 28
  • 48
  • +1 for mentioning the license problem. LGPL in particular requires you to either use a DLL or to distribute your app as object files so others can relink it. – Mark Ransom Jul 01 '14 at 13:20
  • thanks for your answers. ehm. what is about the *.a files? what is their usage? – phön Jul 01 '14 at 13:22
  • I'm guessing for building on linux – Asaf Jul 01 '14 at 13:25
  • how do i know which .lib file i have on my disk? – phön Jul 01 '14 at 13:25
  • @phöööööööööööön - If you link against a .lib file, and your executable requires the relevant DLL file, it's a stub lib. Otherwise, it's a full implementation one. – Asaf Jul 01 '14 at 13:28