The compilation process

前端 未结 5 1073
天涯浪人
天涯浪人 2021-02-03 14:17

Can anyone explain how compilation works?

I can\'t seem to figure out how compilation works..

To be more specific, here\'s an example.. I\'m trying to write some c

5条回答
  •  一向
    一向 (楼主)
    2021-02-03 14:48

    Step 1 - Compiler:

    • Input: Source code file[s]
    • Process: Parsing source code and translating into machine code
    • Output: Object file[s], which consist[s] of:
      • The names of symbols which are defined in this object, and which this object file "exports"
      • The machine code associated with each symbol that's defined in this object file
      • The names of symbols which are not defined in this object file, but on which the software in this object file depends and to which it must subsequently be linked, i.e. names which this object file "imports"

    Step 2 - Linking:

    • Input:
      • Object file[s] from step 1
      • Libraries of other objects (e.g. from the O/S and other software)
    • Process:
      • For each object that you want to link
      • Get the list of symbols which this object imports
      • Find these symbols in other libraries
      • Link the corresponding libraries to your object files
    • Output: a single, executable file, which includes the machine code from all all your objects, plus the objects from libraries which were imported (linked) to your objects.

提交回复
热议问题