Linking

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • questionit
    Contributor
    • Feb 2007
    • 553

    Linking

    What is Linking in a compiler. What does linking do, why is it required?

    Thanks
    qi
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    Linking is the final stage of the build process (often).

    All the compiler does is compile individual C/C++ files to produce object files. After compilation you have as many object files as you had C/C++ source files.

    You then feed all those objects to the linker along with any libraries you want to use, the standard library for instance, and any 3rd party object files you might have been supplied with and the linker pulls them all together into a single executable (assuming no errors).

    One of the main jobs of the linkers is to resolve all the external symbols for each object file. A symbol is normally either a variable or a function and external one is one that you have declared as existing in another file at compilation time. It is the linker that produces unresolved external or multiple defined symbol errors.

    In summary the compiler compiles a single source file into a single object file (but does it multiple times once for each source in the project)). The linker links multiple object files into a single executable.

    Comment

    • questionit
      Contributor
      • Feb 2007
      • 553

      #3
      That was so clear and informative.

      Thanks a lot !!

      Comment

      Working...