source: introduction/important/libraries.xml@ 6ed5123

10.0 10.1 11.0 11.1 11.2 11.3 12.0 12.1 7.10 7.4 7.5 7.6 7.6-blfs 7.6-systemd 7.7 7.8 7.9 8.0 8.1 8.2 8.3 8.4 9.0 9.1 basic bdubbs/svn elogind gnome kde5-13430 kde5-14269 kde5-14686 kea ken/TL2024 ken/inkscape-core-mods ken/tuningfonts krejzi/svn lazarus lxqt nosym perl-modules plabs/newcss plabs/python-mods python3.11 qt5new rahul/power-profiles-daemon renodr/vulkan-addition systemd-11177 systemd-13485 trunk upgradedb xry111/intltool xry111/llvm18 xry111/soup3 xry111/test-20220226 xry111/xf86-video-removal
Last change on this file since 6ed5123 was 6ed5123, checked in by Ken Moffat <ken@…>, 12 years ago

Add pages on libraries and vulnerabilities, icewm-1.3.7, gvolwheel-1.0.0 and retire gnome-media.

git-svn-id: svn://svn.linuxfromscratch.org/BLFS/trunk/BOOK@10406 af4574ff-66df-0310-9fd7-8a98e5e911e0

  • Property mode set to 100644
File size: 6.2 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 <othername>$LastChangedBy$</othername>
13 <date>$Date$</date>
14 </sect1info>
15
16 <title>Libraries: static or shared</title>
17
18 <!-- section g : 'Others' in longindex.html -->
19 <indexterm zone="libraries">
20 <primary sortas="g-libraries">libraries: static or shared</primary>
21 </indexterm>
22
23 <sect2 role="package">
24 <title>Libraries: static or shared</title>
25
26 <para>The original libraries were simply an archive of routines, from which
27 the required routines were extracted and linked into the executable program.
28 These are described as static libraries (libfoo.a). On some old operating
29 systems they are the only type available.</para>
30
31 <para>On almost all Linux platforms we also have shared libraries (libfoo.so)
32 - one copy of the library is loaded into vitual memory, and shared by all the
33 programs which call any of its functions. This is space efficient.</para>
34
35 <para>In the past, essential programs such as a shell were often linked
36 statically so that some form of minimal recovery system would exist even if
37 shared libraries, such as libc.so, became damaged (e,g, moved to
38 <filename class="directory">lost+found</filename> after fsck following an
39 unclean shutdown). Nowadays, most people use an alternative system install,
40 or a Live CD, if they have to recover. Journalling filesystems also reduce
41 the likelihood of this sort of problem.</para>
42
43 <para>Developers, at least while they are developing, often prefer to use
44 static versions of the libraries which their code links to.</para>
45
46 <para>Within the book, there are various places where configure switches
47 such as <command>--disable-static</command> are employed, and other places
48 where the possibility of using system versions of libraries instead of the
49 versions included within another package is discussed. The main reason for
50 this is to simplify updates of libraries.</para>
51
52 <para>If a package is linked to a dynamic library, updating to a newer
53 library version is automatic once the newer library is installed and the
54 program is (re)started (provided the library major version is unchanged,
55 e.g. going from from libfoo.so.2.0 to libfoo.so.2.1 : going to libfoo.so.3
56 will require recompilation - use <command>ldd</command> to find what uses
57 the old version). If a program is linked to a static library, the program
58 always has to be recompiled. If you know which programs linked to a
59 particular static library, this is merely an annoyance. But usually you will
60 <emphasis>not</emphasis> know which programs to recompile.</para>
61
62 <para>Most libraries are shared, but if you do something unusual such as
63 moving a shared library to <filename class="directory">/lib</filename> and
64 accidentally break the <literal>.so</literal> symlink in
65 <filename class="directory">/usr/lib</filename> but keep the static library
66 there, the static library will be silently linked into the programs which
67 need it.</para>
68
69 <para>One way to identify when a static library is used is to deal with it
70 at the end of the installation of every package. Write a script to find all
71 the static libraries in /usr/lib or wherever you are installing to, and
72 either move them to another directory so that they are no longer found by
73 the linker, or rename them so that libfoo.a becomes e.g. libfoo.a.hidden.
74 You can then temporarily restore a static library if it is ever needed, and
75 make a note which package needs it. You may choose to exclude some of the
76 static libraries from glibc if you do this (<filename>libc_nonshared.a,
77 libg.a, libieee.a, libm.a, libpthread_nonshared.a, librpcsvc.a,
78 libsupc++.a</filename> to simplify compilation.</para>
79
80<!-- versions hardcoded in this para, it's a comment on those versions -->
81 <para>If you do that, you may discover that more packages than you were
82 expecting use a static library. That was the case with
83 <application>nettle-2.4</application> in its default static-only configuration:
84 required by <application>GnuTLS-3.0.19</application> but also linked into
85 package(s) which used that, such as
86 <application>glib-networking-2.32.3</application>.</para>
87
88 <para>Many packages put some of their common functions into a static
89 library which is only used by the programs within the package and
90 crucially is <emphasis>not</emphasis> installed as a standalone library.
91 These internal libraries are not a problem - if the package has to be
92 rebuilt to fix a bug or vulnerability, nothing else is linked to them.
93 </para>
94
95 <para>When we speak of System libraries, we mean the shared versions. Some
96 packages such as <xref linkend="firefox"/> and <xref linkend="gs"/> include
97 many other libraries. When they link to them, they link statically so this
98 also makes the programs bigger. The version they ship is often older than
99 the version used in the system, so it may contain bugs - sometimes
100 developers go to the trouble of fixing bugs in their included libraries,
101 other times they do not.</para>
102
103 <para>Sometimes, deciding to use system libraries is an easy decision. Other
104 times it may require you to alter the system version (e.g. for
105 <xref linkend="libpng"/> if used for <xref linkend="firefox"/>).
106 Occasionally a package has an old shipped library, can no longer link to the
107 current version, but can link to a less-old version : the book will usually
108 just use the shipped version. Sometimes the included library is no longer
109 developed separately, or its upstream is now the same as the package&apos;s
110 upstream and you have no other packages which will use it. In those cases,
111 you might decide to use the included static library even if you usually
112 prefer to use system libraries.</para>
113
114 <para condition="html" role="usernotes">User Notes:
115 <ulink url="&blfs-wiki;/libraries"/></para>
116
117 </sect2>
118
119</sect1>
Note: See TracBrowser for help on using the repository browser.