Home > Article > Backend Development > What\'s the Difference Between Static Libraries, Shared Objects, and DLLs in C/C ?
Understanding Static and Shared Libraries
Static libraries (.a files) are incorporated into an application during the linking phase, where a copy of the entire library is integrated into the final executable. Consequently, the application is self-contained, with library functions readily accessible at all times.
In contrast, shared objects (.so files) undergo only a runtime compatibility check against their corresponding header (.h) file during linking. They are not loaded until the runtime phase when required, providing the flexibility to replace the ".so" file without recompiling the application.
The Distinction Between Shared Objects and DLLs
While both shared objects and dynamic link libraries (DLLs) share the ".so" extension, they exhibit some notable differences on Linux and POSIX-compliant systems.
Shared objects are typically loaded automatically when an application starts and remain available as separate entities. DLLs, however, require explicit loading through the dlopen() call within the application.
Shared Archives: A Unique Entity
Shared archives are static libraries that are never used directly by applications. They act as intermediaries, allowing other static libraries to link against them and incorporate specific functions or resources into their own code. Shared archives require special compilation flags (-fPIC and -export-shared) to be shared with dynamic libraries.
Additional Notes from Update
Despite equating shared objects with DLLs, the company where the questioner was employed used the term "DLL" colloquially to refer to shared libraries. Furthermore, the "S" designation for shared archives was a company-specific convention rather than an industry standard.
In summary, static libraries provide self-contained applications, while shared objects offer runtime flexibility without sacrificing code accessibility. Sharing archives bridge the gap between static and shared libraries, allowing functions to be shared across multiple modules.
The above is the detailed content of What\'s the Difference Between Static Libraries, Shared Objects, and DLLs in C/C ?. For more information, please follow other related articles on the PHP Chinese website!