Microsoft KB Archive/57706

From BetaArchive Wiki
< Microsoft KB Archive
Revision as of 17:57, 18 July 2020 by 3155ffGd (talk | contribs) (importing KB archive)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Base


LINK Uses Library Sequence to Resolve External References

Article ID: 57706

Article Last Modified on 10/23/2003



APPLIES TO

  • Microsoft LINK for MS-DOS 2.x
  • Microsoft LINK for MS-DOS 3.x
  • Microsoft LINK for MS-DOS 4.x
  • Microsoft LINK for MS-DOS 5.0x
  • Microsoft LINK for MS-DOS 5.1x
  • Microsoft LINK for MS-DOS 5.2x
  • Microsoft LINK for MS-DOS 5.3x
  • Microsoft LINK for MS-DOS 5.5
  • Microsoft LINK for MS-DOS 5.6
  • Microsoft LINK for OS/2 5.0x
  • Microsoft LINK for OS/2 5.1
  • Microsoft LINK for OS/2 5.11
  • Microsoft LINK for OS/2 5.13
  • Microsoft LINK for OS/2 5.15



This article was previously published under Q57706

SUMMARY

The "MS-DOS Encyclopedia" (Microsoft Press) includes the following statement on pages 407 and 408:

When a public symbol required to resolve an external reference is declared more than once among the object modules in the input libraries, LINK uses the first object module that contains the public symbol. This means that the actual executable code or data associated with a particular external reference can be varied by changing the order in which LINK processes its input libraries...

Each individual library is searched repeatedly (from first library to last, in the sequence in which they are input to LINK) until no further external references can be resolved.


The text below provides additional information about this process.

MORE INFORMATION

As an example, consider the application illustrated by the diagram below:

   Module MAIN   Library A     Library B1    Library C     Library B2
   +---------+  +----------+  +----------+  +----------+  +----------+
   | calls A |  | contains |  | contains |  | contains |  | contains |
   +---------+  |    A,    |  |    B     |  |    C,    |  |    B     |
                | calls  C |  +----------+  | calls  B |  +----------+
                +----------+                +----------+

                

Microsoft LINK determines which copy of Module B the application uses depending on the sequence in which the user specifies the libraries on the linker command line. For example, calling the linker with the following command line selects Module B from Library B2:

LINK MAIN,,,A B1 C B2;


The linker searches Library C first. If it cannot resolve the reference, it continues on to search Library B2. If it still cannot resolve the reference, it returns only then to search Library A and Library B1 to finally resolve the reference.

For a slightly more complex situation, consider the case in which Library contains Module A and Module B, as the diagram below illustrates:

   Module MAIN   Library A    (remove B1)   Library C     Library B2
   +---------+  +----------+               +----------+  +----------+
   | calls A |  | contains |               | contains |  | contains |
   +---------+  |    A,    |               |    C,    |  |    B     |
                | calls  C |               | calls  B |  +----------+
                +----------+               +----------+
                | contains |
                |    B     |
                +----------+

                

With the following command line, the linker selects Module B from Library A:

LINK MAIN,,,A C B2;


Even though the linker always resolves module names using the same rules, as the cases become more complex, it becomes increasingly difficult to determine which version of a module the linker selects. Where feasible, you can avoid this problem by placing the appropriate version of a module into an OBJ file instead of a library. The linker resolves references in OBJ files before it resolves references in libraries.

For more information, please refer to article 20 in the "MS-DOS Encyclopedia," "The Microsoft Object Linker" in the "Object Module Order" section, pages 703-706. Note, however, that this book is currently out of print.


Additional query words: kbinf 1.08 1.10 2.00 2.01 2.10 2.40 2.41 2.44 2.50 3.00 3.01 3.02 3.04 3.05 3.06 3.51 3.55 3.60 3.61 3.64 3.65 3.69 4.06 4.07 4.10 5.01.20 5.01.21 5.02 5.03 5.05 5.10 5.11 5.13 5.15 5.20 5.30 5.31.009 5.50 library search order

Keywords: kb16bitonly KB57706