Linking

Linking

Linking

Compiler Drivers

  • When you run gcc -O2 -g -o p main.c swap.c ,These things happen

    • First the C preprocessor translate main.cpp into main.i

      main.cpp—->(cpp)—->main.i

      cpp main.c /tmp/main.i

    • Then main.i was compiled by C Compiler (cc1) into main.s

      main.i—->(cc1)—->main.s

      cc1 /tmp/main.i main.c -O2 -o /tmp/main.s

    • Then the driver runs the assembler(as) and create a relocatable object file main.o
      main.s—->(as)—->main.o

      as -o /tmp/main.o /tmp/main.s

    • Same things are done for swap.c

    • Finally it runs the linker(ld) which combines main.o and swap.o and other necessary files to create excuteable object file p

      main.o + swap.o + other system object files —->(ld)—->p

  • What is Static Linking

2 thoughts on “Linking

  1. 有本书叫做 链接器与加载器
    你的这个问题如果想深入了解,可以搜一下看看
    纸质版的我打印过一份,在谢海滨那里

Leave a Reply

Your email address will not be published. Required fields are marked *

nineteen − 5 =

This site uses Akismet to reduce spam. Learn how your comment data is processed.