source: introduction/important/libraries.xml@ eede1a3

11.0 ken/refactor-virt lazarus qt5new trunk upgradedb
Last change on this file since eede1a3 was 45ab6c7, checked in by Xi Ruoyao <xry111@…>, 9 months ago

more SVN prop clean up

Remove "$LastChanged$" everywhere, and also some unused $Date$

  • Property mode set to 100644
File size: 6.4 KB
1<?xml version="1.0" encoding="ISO-8859-1"?>
2<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
3 "" [
4 <!ENTITY % general-entities SYSTEM "../../general.ent">
5 %general-entities;
8<sect1 id="libraries" xreflabel="libraries">
9 <?dbhtml filename="libraries.html"?>
11 <sect1info>
12 <date>$Date$</date>
13 </sect1info>
15 <title>Libraries: Static or shared?</title>
17 <!-- section g : 'Others' in longindex.html -->
18 <indexterm zone="libraries">
19 <primary sortas="g-libraries">libraries: static or shared</primary>
20 </indexterm>
22 <sect2 role="package">
23 <title>Libraries: Static or shared?</title>
25 <para>The original libraries were simply an archive of routines from which
26 the required routines were extracted and linked into the executable program.
27 These are described as static libraries (libfoo.a). On some old operating
28 systems they are the only type available.</para>
30 <para>On almost all Linux platforms there are also shared libraries
31 ( - one copy of the library is loaded into virtual memory, and
32 shared by all the programs which call any of its functions. This is space
33 efficient.</para>
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, 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. Journaling filesystems also reduce
41 the likelihood of this sort of problem.</para>
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>
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>
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 to Going to
56 will require recompilation - <command>ldd</command> can be used to find
57 which programs use the old version). If a program is linked to a static
58 library, the program always has to be recompiled. If you know which
59 programs are linked to a particular static library, this is merely an
60 annoyance. But usually you will <emphasis>not</emphasis> know which
61 programs to recompile.</para>
63 <para>Most libraries are shared, but if you do something unusual, such as
64 moving a shared library to <filename class="directory">/lib</filename>
65 accidentally breaking the <literal>.so</literal> symlink in
66 <filename class="directory">/usr/lib</filename> while keeping the static
67 library in <filename class="directory">/lib</filename>, the static library
68 will be silently linked into the programs which need it.</para>
70 <para>One way to identify when a static library is used, is to deal with it
71 at the end of the installation of every package. Write a script to find all
72 the static libraries in <filename class="directory">/usr/lib</filename> or
73 wherever you are installing to, and either move them to another directory so
74 that they are no longer found by the linker, or rename them so that libfoo.a
75 becomes e.g. libfoo.a.hidden. The static library can then be temporarily
76 restored if it is ever needed, and the package needing it can be
77 identified. You may choose to exclude some of the static libraries from
78 glibc if you do this (<filename>libc_nonshared.a, libg.a, libieee.a, libm.a,
79 libpthread_nonshared.a, librpcsvc.a, libsupc++.a</filename>) to simplify
80 compilation.</para>
82<!-- versions hardcoded in this para, it's a comment on those versions -->
83 <para>If you use this approach, you may discover that more packages than
84 you were expecting use a static library. That was the case with
85 <application>nettle-2.4</application> in its default static-only
86 configuration: It was required by <application>GnuTLS-3.0.19</application>,
87 but also linked into package(s) which used
88 <application>GnuTLS</application>, such as
89 <application>glib-networking-2.32.3</application>.</para>
91 <para>Many packages put some of their common functions into a static
92 library which is only used by the programs within the package and,
93 crucially, the library is <emphasis>not</emphasis> installed as a
94 standalone library. These internal libraries are not a problem - if the
95 package has to be rebuilt to fix a bug or vulnerability, nothing else is
96 linked to them.</para>
98 <para>When BLFS mentions system libraries, it means shared versions of
99 libraries. Some packages such as <xref linkend="firefox"/> and
100 <xref linkend="gs"/> include many other libraries. When they link to them,
101 they link statically so this also makes the programs bigger. The version
102 they ship is often older than the version used in the system, so it may
103 contain bugs - sometimes developers go to the trouble of fixing bugs in
104 their included libraries, other times they do not.</para>
106 <para>Sometimes, deciding to use system libraries is an easy decision. Other
107 times it may require you to alter the system version (e.g. for
108 <xref linkend="libpng"/> if used for <xref linkend="firefox"/>).
109 Occasionally, a package ships an old library and can no longer link to
110 the current version, but can link to an older version. In this case, BLFS
111 will usually just use the shipped version. Sometimes the included library
112 is no longer developed separately, or its upstream is now the same as the
113 package&apos;s upstream and you have no other packages which will use it.
114 In those cases, you might decide to use the included static library even if
115 you usually prefer to use system libraries.</para>
117 <para condition="html" role="usernotes">User Notes:
118 <ulink url="&blfs-wiki;/libraries"/></para>
120 </sect2>
Note: See TracBrowser for help on using the repository browser.