Potential of a compiler that creates the executable at once

Walter Bright newshound2 at digitalmars.com
Fri Feb 11 06:33:20 UTC 2022


On 2/10/2022 7:45 PM, max haughton wrote:
> If by hook you mean a callback of sorts that can be overrided, then the problem 
> solved is not strictly the same as a weakly defined function. If you have 
> multiple library's in the same playpen then it simply doesn't work to have them 
> all trying to override the same symbols. If they can neatly hook and unhook 
> things that goes away.

That's not how multiple libraries work.

Suppose you have 3 libraries, A, B, and C. You have an object file X. The linker 
command is:

     link X.obj A.lib B.lib C.lib

X refers to "foo". All 4 define "foo". Which one gets picked?

    X.foo

That's it. There are no unresolved symbols to look for.

Now, suppose only B and C define "foo". Which one gets picked?

    B.foo

because it is not in X. Then, A is looked at, and it is not in A. Then, B is 
looked at, and it is in B. C is not looked at because it is now resolved.

It has nothing to do with weak definitions. It's a simple "foo" is referenced. 
Got to find a definition. Look in the libraries in the order they are supplied 
to the linker.

That's it.

Want to not use the library definition? Define it yourself in X. No need for 
hooking. No need for anything clever at all. Just define it in your .obj file.

----

Now suppose X.obj and Y.obj both define foo. Link with:

     link X.obj Y.obj A.lib B.lib C.lib

You get a message:

     Multiple definition of "foo", found in X.obj and Y.obj

because order does not matter for .obj files as far as symbols go. All the 
symbols in .obj files get added.


More information about the Digitalmars-d mailing list