Object files vs Library files and why?

后端 未结 4 1486
执念已碎
执念已碎 2020-12-22 16:46

I understand the basics of compilation. Source files compiled to object files which the linker then links into executables. These object files are comprised of source files

4条回答
  •  無奈伤痛
    2020-12-22 17:24

    What you describe is how static linking works.

    Why do we have a separate implementation for a library? .a .lib, .dll...

    .dlls are dynamically linked - the linking happens after you run the program. Depending on how you use the library, the function addresses are loaded just after you execute the program, or as late as possible.

    .sos are the same idea, but on Linux.

    .as, traditionally used on Linux (and also in MinGW), are library archives, which behave basically like enhanced object files:

    • they are linked statically.
    • you can pack multiple object files inside single library archive.
    • the names are indexed.

    .libs are used by Microsoft linker in Visual Studio.

    Couldn't someone give you their .o implementations of a certain declaration (.h) and you could replace that in and have it linked to become an executable that performs the same functions, but using different operations?

    Yes! With dynamic libraries, you can go even further: you can replace the library without recompiling, sometimes even without restarting the program.

    The practical example is Wine - they provide open-sourced and portable implementation of WinAPI.

提交回复
热议问题