source: introduction/important/libraries.xml@ 450ac18

11.2 11.3 12.0 12.1 kea ken/TL2024 ken/inkscape-core-mods ken/tuningfonts lazarus lxqt plabs/newcss plabs/python-mods python3.11 qt5new rahul/power-profiles-daemon renodr/vulkan-addition trunk xry111/llvm18 xry111/soup3 xry111/xf86-video-removal
Last change on this file since 450ac18 was 450ac18, checked in by Pierre Labastie <pierre.labastie@…>, 21 months ago

Update and tidy up the page about libraries

Prompted by a somewhat unhelpful comment in a mail of R Tegner.

  • Property mode set to 100644
File size: 7.0 KB
Line 
1<?xml version="1.0" encoding="ISO-8859-1"?>
2<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
3 "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
4 <!ENTITY % general-entities SYSTEM "../../general.ent">
5 %general-entities;
6]>
7
8<sect1 id="libraries" xreflabel="libraries">
9 <?dbhtml filename="libraries.html"?>
10
11 <sect1info>
12 <date>$Date$</date>
13 </sect1info>
14
15 <title>Libraries: Static or shared?</title>
16
17 <!-- section g : 'Others' in longindex.html -->
18 <indexterm zone="libraries">
19 <primary sortas="g-libraries">libraries: static or shared</primary>
20 </indexterm>
21
22 <sect2 role="package">
23 <title>Libraries: Static or shared?</title>
24
25 <para>
26 The original libraries were simply an archive of routines from which
27 the required routines were extracted and linked into the executable
28 program.These are described as static libraries, with names of the form
29 <filename>libfoo.a</filename> on UNIX-like operating systems.
30 On some old operating systems they are the only type available.
31 </para>
32
33 <para>
34 On almost all Linux platforms there are also <quote>shared</quote>
35 (or equivalently <quote>dynamic</quote>)
36 libraries (with names of the form <filename>libfoo.so</filename>) &ndash;
37 one copy of the library is loaded into virtual memory, and shared by
38 all the programs which call any of its functions. This is space
39 efficient.
40 </para>
41
42 <para>
43 In the past, essential programs such as a shell were often linked
44 statically so that some form of minimal recovery system would exist even
45 if shared libraries, such as <filename>libc.so</filename>, became
46 damaged (e.g. moved to <filename class="directory">lost+found</filename>
47 after <command>fsck</command> following an unclean shutdown). Nowadays,
48 most people use an alternative system install or a USB stick if they
49 have to recover. Journaling filesystems also reduce the likelihood of
50 this sort of problem.
51 </para>
52
53<!-- really?
54 <para>
55 Developers, at least while they are developing, often prefer to use
56 static versions of the libraries which their code links to.
57 </para>
58-->
59 <para>
60 Within the book, there are various places where configure switches
61 such as <parameter>--disable-static</parameter> are employed, and
62 other places where the possibility of using system versions of
63 libraries instead of the versions included within another package is
64 discussed. The main reason for this is to simplify updates of libraries.
65 </para>
66
67 <para>
68 If a package is linked to a dynamic library, updating to a newer
69 library version is automatic once the newer library is installed and the
70 program is (re)started (provided the library major version is unchanged,
71 e.g. going from <filename>libfoo.so.2.0</filename> to
72 <filename>libfoo.so.2.1</filename>. Going to
73 <filename>libfoo.so.3</filename> will require recompilation &ndash;
74 <command>ldd</command> can be used to find which programs use the old
75 version). If a program is linked to a static
76 library, the program always has to be recompiled. If you know which
77 programs are linked to a particular static library, this is merely an
78 annoyance. But usually you will <emphasis>not</emphasis> know which
79 programs to recompile.
80 </para>
81<!-- obsolete with /usr merge
82 <para>Most libraries are shared, but if you do something unusual, such as
83 moving a shared library to <filename class="directory">/lib</filename>
84 accidentally breaking the <literal>.so</literal> symlink in
85 <filename class="directory">/usr/lib</filename> while keeping the static
86 library in <filename class="directory">/lib</filename>, the static library
87 will be silently linked into the programs which need it.</para>
88-->
89 <para>
90 One way to identify when a static library is used, is to deal with
91 it at the end of the installation of every package. Write a script
92 to find all the static libraries in <filename
93 class="directory">/usr/lib</filename> or wherever you are installing
94 to, and either move them to another directory so that they are no
95 longer found by the linker, or rename them so that
96 <filename>libfoo.a</filename> becomes
97 e.g. <filename>libfoo.a.hidden</filename>. The static library can then
98 be temporarily restored if it is ever needed, and the package needing
99 it can be identified. This shoudn't be done blindly since many
100 libraries only exist in a static version. For example, some libraries
101 from the <application>glibc</application> and
102 <application>gcc</application> packages should always be
103 present on the system (<filename>libc_nonshared.a, libg.a,
104 libpthread_nonshared.a, libssp_nonshared.a, libsupc++.a</filename>
105 as of glibc-2.36 and gcc-12.2).
106 </para>
107
108<!-- versions hardcoded in this para, it's a comment on those versions -->
109 <para>If you use this approach, you may discover that more packages than
110 you were expecting use a static library. That was the case with
111 <application>nettle-2.4</application> in its default static-only
112 configuration: It was required by <application>GnuTLS-3.0.19</application>,
113 but also linked into package(s) which used
114 <application>GnuTLS</application>, such as
115 <application>glib-networking-2.32.3</application>.</para>
116
117 <para>Many packages put some of their common functions into a static
118 library which is only used by the programs within the package and,
119 crucially, the library is <emphasis>not</emphasis> installed as a
120 standalone library. These internal libraries are not a problem &ndash; if
121 the package has to be rebuilt to fix a bug or vulnerability, nothing else is linked to them.</para>
122
123 <para>When BLFS mentions system libraries, it means shared versions of
124 libraries. Some packages such as <xref linkend="firefox"/> and
125 <xref linkend="gs"/> bundle many other libraries in their build tree.
126 The version they ship is often older than the version used in the system,
127 so it may contain bugs &ndash; sometimes developers go to the trouble of
128 fixing bugs in their included libraries, other times they do not.</para>
129
130 <para>Sometimes, deciding to use system libraries is an easy decision.
131 Other times it may require you to alter the system version (e.g. for
132 <xref linkend="libpng"/> if used for <xref linkend="firefox"/>).
133 Occasionally, a package ships an old library and can no longer link to
134 the current version, but can link to an older version. In this case, BLFS
135 will usually just use the shipped version. Sometimes the included library
136 is no longer developed separately, or its upstream is now the same as the
137 package&apos;s upstream and you have no other packages which will use it.
138 In those cases, you'll be lead to use the included library even if
139 you usually prefer to use system libraries.</para>
140
141 <para condition="html" role="usernotes">User Notes:
142 <ulink url="&blfs-wiki;/libraries"/></para>
143
144 </sect2>
145
146</sect1>
Note: See TracBrowser for help on using the repository browser.