Re: how do static import libraries actually work?



Hi Tim Roberts,

Thank you.

"I could create an import library called xxx.lib that contained an entry
for
MyEntryPoint that points to YourEntryPoint in zzz.dll. " - How?

--
Thanks & Regards,
John.


"Tim Roberts" wrote:

kilik3000@xxxxxxxxx wrote:

One thing I've never really understood are import libraries for DLLs
on Windows.

For example, let's say that I use a function from user32.dll in my
code. Without linking to user32.lib in VS I get a link error, so I
link to user32.lib and all is well.

I guess what I don't understand is how this jives with static linking
and dynamic linking.

From what I understand, static linking is when you take object code
and just plop it into your binary.

Dynamic linking (on windows at least) is when you call LoadLibray()
and then GetProcAddress() and then make your call on a function
pointer.

What happens when you statically link to a DLL import library (i.e.
user32.lib)?

Does the import library object code contain implicit calls to
LoadLibray() and GetProcAddress that are performed on your behalf?

It is kind of an interesting process. The object file produced by the
compiler just calls, for example, CreateWindowA. The object file doesn't
know where that entry point will come from, it relies on the linker to fix
it.

In this particular case, the CreateWindowA entry point will be found in
user32.lib. But the library entry for CreateWindowA doesn't actually
contain any code. Instead, it contains a special linker table that says
"this entry point is found in CreateWindowA in user32.dll". The linker
creates an entry in the import descriptor table in the resulting
executable.

Although it is most common for the library entry point name to match the
DLL entry point name, and it is also most common for all of the imports in
a single library to point to a single DLL, neither is required. I could
create an import library called xxx.lib that contained an entry for
MyEntryPoint that points to YourEntryPoint in zzz.dll.

When the executable is loaded, the OS loader runs through the import
descriptor table, loads all of the DLLs that are mentioned, and fixes up
the addresses.
--
Tim Roberts, timr@xxxxxxxxx
Providenza & Boekelheide, Inc.

.



Relevant Pages

  • Re: ENTRY statement
    ... produce libraries that contain a Fortran77 style alias (for example I ...    end interface ... These all have some advantages and disadvantages compared to entry ... For procedures to be used by Fortran 90 and higher compilers these ...
    (comp.lang.fortran)
  • Re: how do static import libraries actually work?
    ... One thing I've never really understood are import libraries for DLLs ... What happens when you statically link to a DLL import library (i.e. ... compiler just calls, for example, CreateWindowA. ... know where that entry point will come from, it relies on the linker to fix ...
    (microsoft.public.vc.language)
  • Re: compile+link Fujitsu Linux
    ... Red Hat Linux 7.2, Locale C ... There is no Cobol syntax to specify a library name. ... It searches only the libraries named in the executable's ELF ... Libraries normally contain many programs and entry points. ...
    (comp.lang.cobol)
  • Re: linking to libraries on A series
    ... Some languages cannot directly talk to system libraries, and you need to write a jacket library to translate parameters and results from one environment to the other. ... There is no explicit library linkage call, at least in COBOL. ... The first time a program calls an entry point in a server library, the MCP traps the call, checks for compatible parameter sequences, sets up the address linkage, and restarts the call. ...
    (comp.sys.unisys)
  • RE: Dynamic Linking Increases Program Size
    ... Wouldn't we get duplicate symbol errors if linking ... with both the static and DLL libraries? ... Note that the largest of the two libraries exports ... Most of these are annoying little functors. ...
    (microsoft.public.windowsce.embedded.vc)