I am looking at some c++/c code, the open source ovaldi project. I see that they include pcre.dll in the distribution and are making calls to functions in that library in the code; but they never load the dll; they just include the pcre.h header and seem to have access t开发者_运维问答o the functions. Are they really just building with a static library and distributing pcre.dll on accident or is there a way to do this?
What do you mean they don't load the DLL? Not calling LoadLibrary
? Probably are using an import table, the OS loader will load the DLL automatically.
They DO load the dll, but just implicitly. You see, you can create a .lib file which is responsible for loading the dll and redirecting calls, link to the lib, include the header and that's it. In Visual Studio this is done automatically, when you set a dependency to a dll project
The application itself can be built with linker indications to automatically find and load the DLL without needing to do so explicitly. True dynamic loading of DLLs is usually only needed when the question is which version of a DLL to load.
You can load dynamic libraries at startup, but then you're required to restart the program to reload the library if the library changes. Loading the library during runtime with LoadLibrary
or dlopen
(unix) allows you to update a dynamic library while the process is running. This is good for long running processes such as a server, but it also incurs extra overhead for reloading the library.
精彩评论