Static library & Dynamic library : Confusion

前端 未结 3 2118
栀梦
栀梦 2020-12-29 15:36

I need little clarification in this area. I feel that the terms Static library & Dynamic Library are not correct.

  • lib1.o + lib2.o
3条回答
  •  梦谈多话
    2020-12-29 16:19

    Static libraries contain code that is copied into the executable. Code in the library that isn't referenced by your program is removed. A program with only static libraries doesn't have any dependencies during runtime.

    Dynamic libraries are linked during runtime -- a program with references to a dynamic library will load and link with the library when it starts up (or on demand).

    A Relocatable library is another word for a dynamic library. When you link with a dynamic library, the addresses of the functions contained within are computed, based on where the library is loaded in memory. They are "relocatable" because the addresses of the contained functions are not determined at link time. (In a static library, the addresses are computed during link time.)

    An object file (.o) contains compiled code, but doesn't contain the final addresses of all of the functions. Linking is the process where the linker goes through all of the object files and computes the correct address for each function that is called.

提交回复
热议问题