I looked at this page: An In-Depth Look into the Win32 Portable Executable File Format
It explains that the linker needs an import library because the compiler can't distinguish between normal function calls and API-function calls. But they say also that __declspec(dllimport) specifies a function call to be an API-Call so the linker links against __imp_[function-name]
. But with this keyword the compiler should know that this is a call to an API-Function.
Why does the linker still need an import library? The compiler could mark this symbol as imported by prepending __imp_
to the function name and could make a call to a function pointer (which is an unresolved symbol yet) and the linker could replace this symbol (because it sees that this an API call) with the IAT entry's address.
And why can the MinGW-linker use "MinGW-DLLs" directly but the Visual-Studio linker needs an import library?
As I read the post some other questions were also raised. How does the "dlltool (or linker)" (whichever creates the import library) know the location of an IAT entry before linkage with the final executable has been done? I thought the IAT entries would be constructed at link-time with the final executable. The post said, that every API-Call has a fixed position in the IAT table, never-mind how many DLLs will be linked. I cannot imagine how that could be achieved.