Coder Perfect

What is the difference between the library,.la, and.a?


I understand that file is a type of dynamic library (lots of threads can share such libraries so there is no need to have more than one copy of it in memory). What’s the difference between.a, though? Are all of these libraries static?

Why are there so many static libraries while dynamic libraries have so many advantages? When should I attempt to compile code or.a?

[mirror@home ins_openvpn]$ ls lib/openvpn/plugins/ -l
total 96
-rw-r--r-- 1 mirror mirror 22892 Sep  2 23:25 openvpn-plugin-auth-pam.a
-rwxr-xr-x 1 mirror mirror   931 Sep  2 23:25
-rwxr-xr-x 1 mirror mirror 23621 Sep  2 23:25
-rw-r--r-- 1 mirror mirror 17228 Sep  2 23:25 openvpn-plugin-down-root.a
-rwxr-xr-x 1 mirror mirror   932 Sep  2 23:25
-rwxr-xr-x 1 mirror mirror 18805 Sep  2 23:25

Asked by hugemeow

Solution #1

Dynamic libraries files. Because all the apps that are linked with the library use the same file rather than producing a copy in the final executable, the suffix stands for “shared object.”

Static libraries are stored in.a files. The suffix stands for “archive”, because they’re actually just an archive (made with the ar command — a predecessor of tar that’s now just used for making libraries) of the original .o object files.

.la files are text files that the GNU “libtools” package uses to describe the files that make up a library. More information about them can be found in this question: What is the purpose of the file?

Static and dynamic libraries each have pros and cons.

Static pro: Because the user always utilizes the library version that you’ve tested with your program, there shouldn’t be any unexpected compatibility issues.

Static disadvantage: If a library bug is fixed, you must redistribute your program to take benefit of it. You might need to do this anyhow, unless it’s a library that users are likely to update on their own.

Dynamic benefit: The memory footprint of your process is reduced since the library’s memory is amortized across all processes that use it.

Dynamic pro: Libraries may be loaded dynamically during runtime, which is useful for plugins because it eliminates the need to select plugins when creating and installing the software. New plugins can be installed at any time.

Dynamic disadvantage: The library may not exist on the system where the application is being installed, or it may exist in a version that is incompatible with the application. To avoid this, the application package may need to include a copy of the library so that it may be installed if needed. Package managers, which can obtain and install any necessary dependencies, can also help with this.

Dynamic disadvantage: Because link-time optimization is rarely achievable, there may be efficiency consequences in high-performance systems. WPO and LTO are discussed in Wikipedia.

System libraries, such as libc, benefit greatly from dynamic libraries. Because kernel interfaces have evolved, these libraries frequently need to incorporate code that is depending on the specific OS and version. When you link a program to a static system library, it will only operate on the OS version for which the library was developed. If you use a dynamic library, however, it will automatically use the library that is installed on the system you’re using.

Answered by Barmar

Solution #2

that specifies the executable’s referenced component A shared library, on the other hand, is similar to a single large object file that contains all other object files. As a result, if you call a symbol in shared lib, the executable will reference all object files.

Answered by Fatih

Post is based on