source: introduction/important/la-files.xml@ b3c16f12

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/xf86-video-removal
Last change on this file since b3c16f12 was b3c16f12, checked in by Xi Ruoyao <xry111@…>, 19 months ago

la-files: some reword

  • libtool is usually internally shipped and system libtool is not used. Or we can simply patch system libtool to stop installing .la files...
  • Add a paragraph about static library. Prevent anyone from thinking "oh I need static libraries and I'll keep those .la files".
  • Mention that .la file may mistakenly include library names or paths not valid after installation.
  • Move a </literal> into the correct location.
  • Property mode set to 100644
File size: 5.4 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="la-files" xreflabel="Libtool archive (.la) files">
9 <?dbhtml filename="la-files.html"?>
10
11 <sect1info>
12 <date>$Date$</date>
13 </sect1info>
14
15 <title>About Libtool Archive (.la) files</title>
16
17 <!-- section g : 'Others' in longindex.html -->
18 <indexterm zone="la-files">
19 <primary sortas="g-la-files">Library archive (.la) files</primary>
20 </indexterm>
21
22 <sect2 role="package">
23 <title>Files with a .la extension</title>
24
25 <para>
26
27 In LFS and BLFS, many packages use a internally shipped libtool copy to
28 build on a variety of Unix platforms. This includes platforms such as
29 AIX, Solaris, IRIX, HP-UX, and Cygwin as well as Linux. The origins of
30 this tool are quite dated. It was intended to manage libraries on
31 systems with less advanced capabilities than a modern Linux system.
32
33 </para>
34
35 <para>
36
37 On a Linux system, libtool specific files are generally unneeded.
38 Normally libraries are specified in the build process during the link
39 phase. Since a linux system uses the <ulink
40 url="https://en.wikipedia.org/wiki/Executable_and_Linkable_Format">
41 Executable and Linkable Format (ELF)</ulink> for executables and
42 dynamic libraries, information needed to complete the task is embedded
43 in the files. Both the linker and the program loader can query the
44 appropriate files and properly link or execute the program.
45
46 </para>
47
48 <para>
49 Static libraries are rarely used in LFS and BLFS. And, nowadays most
50 packages store the information needed for linking against a static
51 library into a .pc file, instead of relying on libtool.
52 A <command>pkg-config --static --libs</command> command will output
53 the sufficient flags for the linker to link against a static library
54 without any libtool magic.
55 </para>
56
57 <para>
58 The problem is that libtool usually creates one or more text files for
59 package libraries called libtool archives. These small files have a
60 ".la" extension and contain information that is similar to that embedded
61 in the libraries or pkg-config files. When building a package that
62 uses libtool, the process automatically looks for these files.
63 Sometimes a .la file can contains the name or path of a static library
64 used during build but not installed, then the build process will break
65 because the .la file refers to something nonexistent on the system.
66 Similarly, if a package is updated and no longer uses the .la file,
67 then the build process can break with the old .la files.
68 </para>
69
70 <para>
71
72 The solution is to remove the .la files. However there is a catch.
73 Some packages, such as <xref linkend='imagemagick'/>, use a libtool
74 function, lt_dlopen, to load libraries as needed during execution and
75 resolve their dependencies at run time. In this case, the .la files
76 should remain.
77
78 </para>
79
80 <para>
81
82 The script below, removes all unneeded .la files and saves them in a
83 directory, /var/local/la-files by default, not in the normal library
84 path. It also searches all pkg-config files (.pc) for embedded
85 references to .la files and fixes them to be conventional library
86 references needed when an application or library is built. It
87 can be run as needed to clean up the directories that may be causing
88 problems.
89
90 </para>
91
92<screen role="root"><userinput>cat &gt; /usr/sbin/remove-la-files.sh &lt;&lt; "EOF"
93<literal>#!/bin/bash
94
95# /usr/sbin/remove-la-files.sh
96# Written for Beyond Linux From Scratch
97# by Bruce Dubbs &lt;bdubbs@&lfs-domainname;&gt;
98
99# Make sure we are running with root privs
100if test "${EUID}" -ne 0; then
101 echo "Error: $(basename ${0}) must be run as the root user! Exiting..."
102 exit 1
103fi
104
105# Make sure PKG_CONFIG_PATH is set if discarded by sudo
106source /etc/profile
107
108OLD_LA_DIR=/var/local/la-files
109
110mkdir -p $OLD_LA_DIR
111
112# Only search directories in /opt, but not symlinks to directories
113OPTDIRS=$(find /opt -mindepth 1 -maxdepth 1 -type d)
114
115# Move any found .la files to a directory out of the way
116find /usr/lib $OPTDIRS -name "*.la" ! -path "/usr/lib/ImageMagick*" \
117 -exec mv -fv {} $OLD_LA_DIR \;
118###############
119
120# Fix any .pc files that may have .la references
121
122STD_PC_PATH='/usr/lib/pkgconfig
123 /usr/share/pkgconfig
124 /usr/local/lib/pkgconfig
125 /usr/local/share/pkgconfig'
126
127# For each directory that can have .pc files
128for d in $(echo $PKG_CONFIG_PATH | tr : ' ') $STD_PC_PATH; do
129
130 # For each pc file
131 for pc in $d/*.pc ; do
132 if [ $pc == "$d/*.pc" ]; then continue; fi
133
134 # Check each word in a line with a .la reference
135 for word in $(grep '\.la' $pc); do
136 if $(echo $word | grep -q '.la$' ); then
137 mkdir -p $d/la-backup
138 cp -fv $pc $d/la-backup
139
140 basename=$(basename $word )
141 libref=$(echo $basename|sed -e 's/^lib/-l/' -e 's/\.la$//')
142
143 # Fix the .pc file
144 sed -i "s:$word:$libref:" $pc
145 fi
146 done
147 done
148done</literal>
149
150EOF
151
152chmod +x /usr/sbin/remove-la-files.sh</userinput></screen>
153
154 <para condition="html" role="usernotes">
155 User Notes: <ulink url="&blfs-wiki;/la-files"/>
156 </para>
157
158 </sect2>
159
160</sect1>
Note: See TracBrowser for help on using the repository browser.