Reputation: 3955
I have searched the web , but with different answers to my query. I am not an expert with Windows but I would like to understand it exactly.
When an application is compiled for Windows, which will involve the need for runtime-linking of libraries (DLLs), like using a core library kernel32.dll or some other user-created dll, does the application need to know that the dll exists before run-time.
I have read that a dll must be accompanied by a .lib file which must be linked in at compile time but somewhere it states that the .lib file is not required.
Does the application just execute and expect that it will find the functions needed in a dll and just fail if not found?
Thanks in advance.
Upvotes: 2
Views: 739
Reputation: 5775
List of dynamically linked functions is kept in import section of PECOFF executable file, as defined with the second directory item in optional header. Usual name of the section is .idata or IMPORT. The only necessary information kept in the import directory is
So the answer is negative, linker does not need to know anything about the DLL and it doesn't necessarily need to exist at link-time. It is the loader's job to find the refered DLL at run-time (and report error Entry point FunctionName was not found in the library eventually).
Import libraries .lib exist because of older compilers and linkers which lack the directive to declare imported function and its DLL, so they need the linked library which contains import definition and also indirect proxy jumps to IAT. But good linker doesn't need this, as this information can be created on the fly.
Upvotes: -1