0

I don't think this is a duplicate to the other question. Because that one is about actual dynamic vs static LIBRARY. Not implicit/explic LINKING of a dynamic library.

In my current project, I have to confront with the library for the first time. I read a lot of stuff about static library and dll and so far, thats what I understand (hopefully someone can point out my mistake if I understand anything wrong). I'm using qt creator by the way.

First of all, theres static library and static linking. It creates a .lib-file which contains all the functions and can be added (static linked into?) an application. In my case, added to the pro.file of the project. The library will be load before the app starts. And if 10 programm use the same functions from a static library, this will be loaded 10 times into the memory.

To avoid this, dynamic linking can be used. In this case, a dynamic link library(dll) can be loaded implicitly(load-time linking, but to cause me confusion at the beginning, sometimes called static linking too) or explicitly(run-time linking).

An import library(.lib) and a .dll are created when building a dll. With implicit linking, the import library, which doesn't contains any actual functions but only code which points to the dll, will be linked to the project like a static library(added to the .pro-file). The linker adds information to the .exe where to find the dll. When programm starts, the system uses the information in the .exe to try to find the dll. terminate the programm if dll cant be found. else load the functions from dll into memory.

With explicit linking, the compiler doesn't know anything about the dll, this will be load at run time using functions from the system (LoadLibrary in Windows), which loads the dll by his filename and returns a handle of the library. The handle can be used then with GetProcAdress to get access to the functions in the dll. Is it necessary to add the .lib-file to the .pro-file too?

I choosed the implicit linking, simply because it seems "easier" to me. Is there any other advantages to link a dll implicitly?

yangsunny
  • 656
  • 5
  • 13
  • 32
  • Easier is good enough in this case. The only reason for explicit linking is when you can't be certain the DLL will be present on the host system, you need to choose which DLL to load at runtime, or some other unusual case that doesn't apply to the majority of applications. – Carey Gregory Apr 17 '16 at 14:51
  • @CareyGregory which means, using explicit loading then, when I want the application to start even the dll is not present on the system. In this case, the dlls are some kind of programmparts, which can be loaded into the application, but dont have to be. Such like an adblock plugin for a browser. Is that right? – yangsunny Apr 17 '16 at 14:59
  • Correct. If a browser intrinsically linked to a plugin's DLL, that plugin would have to be present for the browser to run. – Carey Gregory Apr 17 '16 at 16:07

0 Answers0