How does the linker know where is the definition of an extern function?

后端 未结 4 1098
日久生厌
日久生厌 2021-01-12 07:29

I read a few posts and concluded that extern tells compiler that \"This function exists, but the code for it is somewhere else. Don\'t panic.\" But how does the linker know

4条回答
  •  逝去的感伤
    2021-01-12 07:56

    Linking usually happens this way: The command line is iterated over and every argument given is

    1. used directly if it is an object file,
    2. used in the extent needed (=to fulfill all references which are unresolved till now).

    At the end, every reference has to be fulfilled in order to successfully link. The order of lines given at the linker command line is important.

提交回复
热议问题