what is the difference between linking and loading in c language

后端 未结 7 1662
庸人自扰
庸人自扰 2021-02-04 06:15

Does linking and loading of the the dynamic libraries both happen at runtime? or is it that only loading of the library happens at run time?

7条回答
  •  我在风中等你
    2021-02-04 07:00

    Both happen at runtime for dynamic libraries.

    First, the libraries are loaded, along with all their dependencies (and those libraries' dependencies, and so on). Then the dynamic linker resolves symbols in the loaded libraries. Usually both of these functions are implemented by the same piece of software; on Linux it's ld.so.

    Symbols in static libraries are resolved at link time and included in the executable file itself. Static libraries may, however, have unresolved symbols that are satisfied at runtime by dynamic libraries.

    There's an in-depth description of how this happens, how names are hashed, how expensive it is to resolve symbols at runtime, etc. in How to Write Shared Libraries.

提交回复
热议问题