1ExtUtils::Liblist(3) User Contributed Perl Documentation ExtUtils::Liblist(3)
2
3
4
6 ExtUtils::Liblist - determine libraries to use and how to use them
7
9 require ExtUtils::Liblist;
10
11 $MM->ext($potential_libs, $verbose, $need_names);
12
13 # Usually you can get away with:
14 ExtUtils::Liblist->ext($potential_libs, $verbose, $need_names)
15
17 This utility takes a list of libraries in the form "-llib1 -llib2
18 -llib3" and returns lines suitable for inclusion in an extension
19 Makefile. Extra library paths may be included with the form
20 "-L/another/path" this will affect the searches for all subsequent
21 libraries.
22
23 It returns an array of four or five scalar values: EXTRALIBS,
24 BSLOADLIBS, LDLOADLIBS, LD_RUN_PATH, and, optionally, a reference to
25 the array of the filenames of actual libraries. Some of these don't
26 mean anything unless on Unix. See the details about those platform
27 specifics below. The list of the filenames is returned only if
28 $need_names argument is true.
29
30 Dependent libraries can be linked in one of three ways:
31
32 • For static extensions
33
34 by the ld command when the perl binary is linked with the extension
35 library. See EXTRALIBS below.
36
37 • For dynamic extensions at build/link time
38
39 by the ld command when the shared object is built/linked. See
40 LDLOADLIBS below.
41
42 • For dynamic extensions at load time
43
44 by the DynaLoader when the shared object is loaded. See BSLOADLIBS
45 below.
46
47 EXTRALIBS
48 List of libraries that need to be linked with when linking a perl
49 binary which includes this extension. Only those libraries that
50 actually exist are included. These are written to a file and used when
51 linking perl.
52
53 LDLOADLIBS and LD_RUN_PATH
54 List of those libraries which can or must be linked into the shared
55 library when created using ld. These may be static or dynamic
56 libraries. LD_RUN_PATH is a colon separated list of the directories in
57 LDLOADLIBS. It is passed as an environment variable to the process that
58 links the shared library.
59
60 Fedora extension: This generation of LD_RUN_PATH is disabled by
61 default. To use the generated LD_RUN_PATH for all links, set the
62 USE_MM_LD_RUN_PATH MakeMaker object attribute / argument, (or set the
63 $USE_MM_LD_RUN_PATH environment variable).
64
65 BSLOADLIBS
66 List of those libraries that are needed but can be linked in
67 dynamically at run time on this platform. SunOS/Solaris does not need
68 this because ld records the information (from LDLOADLIBS) into the
69 object file. This list is used to create a .bs (bootstrap) file.
70
72 This module deals with a lot of system dependencies and has quite a few
73 architecture specific "if"s in the code.
74
75 VMS implementation
76 The version of ext() which is executed under VMS differs from the
77 Unix-OS/2 version in several respects:
78
79 • Input library and path specifications are accepted with or without
80 the "-l" and "-L" prefixes used by Unix linkers. If neither prefix
81 is present, a token is considered a directory to search if it is in
82 fact a directory, and a library to search for otherwise. Authors who
83 wish their extensions to be portable to Unix or OS/2 should use the
84 Unix prefixes, since the Unix-OS/2 version of ext() requires them.
85
86 • Wherever possible, shareable images are preferred to object
87 libraries, and object libraries to plain object files. In accordance
88 with VMS naming conventions, ext() looks for files named libshr and
89 librtl; it also looks for liblib and liblib to accommodate Unix
90 conventions used in some ported software.
91
92 • For each library that is found, an appropriate directive for a linker
93 options file is generated. The return values are space-separated
94 strings of these directives, rather than elements used on the linker
95 command line.
96
97 • LDLOADLIBS contains both the libraries found based on $potential_libs
98 and the CRTLs, if any, specified in Config.pm. EXTRALIBS contains
99 just those libraries found based on $potential_libs. BSLOADLIBS and
100 LD_RUN_PATH are always empty.
101
102 In addition, an attempt is made to recognize several common Unix
103 library names, and filter them out or convert them to their VMS
104 equivalents, as appropriate.
105
106 In general, the VMS version of ext() should properly handle input from
107 extensions originally designed for a Unix or VMS environment. If you
108 encounter problems, or discover cases where the search could be
109 improved, please let us know.
110
111 Win32 implementation
112 The version of ext() which is executed under Win32 differs from the
113 Unix-OS/2 version in several respects:
114
115 • If $potential_libs is empty, the return value will be empty.
116 Otherwise, the libraries specified by $Config{perllibs} (see
117 Config.pm) will be appended to the list of $potential_libs. The
118 libraries will be searched for in the directories specified in
119 $potential_libs, $Config{libpth}, and in
120 "$Config{installarchlib}/CORE". For each library that is found, a
121 space-separated list of fully qualified library pathnames is
122 generated.
123
124 • Input library and path specifications are accepted with or without
125 the "-l" and "-L" prefixes used by Unix linkers.
126
127 An entry of the form "-La:\foo" specifies the "a:\foo" directory to
128 look for the libraries that follow.
129
130 An entry of the form "-lfoo" specifies the library "foo", which may
131 be spelled differently depending on what kind of compiler you are
132 using. If you are using GCC, it gets translated to "libfoo.a", but
133 for other win32 compilers, it becomes "foo.lib". If no files are
134 found by those translated names, one more attempt is made to find
135 them using either "foo.a" or "libfoo.lib", depending on whether GCC
136 or some other win32 compiler is being used, respectively.
137
138 If neither the "-L" or "-l" prefix is present in an entry, the entry
139 is considered a directory to search if it is in fact a directory, and
140 a library to search for otherwise. The $Config{lib_ext} suffix will
141 be appended to any entries that are not directories and don't already
142 have the suffix.
143
144 Note that the "-L" and "-l" prefixes are not required, but authors
145 who wish their extensions to be portable to Unix or OS/2 should use
146 the prefixes, since the Unix-OS/2 version of ext() requires them.
147
148 • Entries cannot be plain object files, as many Win32 compilers will
149 not handle object files in the place of libraries.
150
151 • Entries in $potential_libs beginning with a colon and followed by
152 alphanumeric characters are treated as flags. Unknown flags will be
153 ignored.
154
155 An entry that matches "/:nodefault/i" disables the appending of
156 default libraries found in $Config{perllibs} (this should be only
157 needed very rarely).
158
159 An entry that matches "/:nosearch/i" disables all searching for the
160 libraries specified after it. Translation of "-Lfoo" and "-lfoo"
161 still happens as appropriate (depending on compiler being used, as
162 reflected by $Config{cc}), but the entries are not verified to be
163 valid files or directories.
164
165 An entry that matches "/:search/i" reenables searching for the
166 libraries specified after it. You can put it at the end to enable
167 searching for default libraries specified by $Config{perllibs}.
168
169 • The libraries specified may be a mixture of static libraries and
170 import libraries (to link with DLLs). Since both kinds are used
171 pretty transparently on the Win32 platform, we do not attempt to
172 distinguish between them.
173
174 • LDLOADLIBS and EXTRALIBS are always identical under Win32, and
175 BSLOADLIBS and LD_RUN_PATH are always empty (this may change in
176 future).
177
178 • You must make sure that any paths and path components are properly
179 surrounded with double-quotes if they contain spaces. For example,
180 $potential_libs could be (literally):
181
182 "-Lc:\Program Files\vc\lib" msvcrt.lib "la test\foo bar.lib"
183
184 Note how the first and last entries are protected by quotes in order
185 to protect the spaces.
186
187 • Since this module is most often used only indirectly from extension
188 "Makefile.PL" files, here is an example "Makefile.PL" entry to add a
189 library to the build process for an extension:
190
191 LIBS => ['-lgl']
192
193 When using GCC, that entry specifies that MakeMaker should first look
194 for "libgl.a" (followed by "gl.a") in all the locations specified by
195 $Config{libpth}.
196
197 When using a compiler other than GCC, the above entry will search for
198 "gl.lib" (followed by "libgl.lib").
199
200 If the library happens to be in a location not in $Config{libpth},
201 you need:
202
203 LIBS => ['-Lc:\gllibs -lgl']
204
205 Here is a less often used example:
206
207 LIBS => ['-lgl', ':nosearch -Ld:\mesalibs -lmesa -luser32']
208
209 This specifies a search for library "gl" as before. If that search
210 fails to find the library, it looks at the next item in the list. The
211 ":nosearch" flag will prevent searching for the libraries that
212 follow, so it simply returns the value as "-Ld:\mesalibs -lmesa
213 -luser32", since GCC can use that value as is with its linker.
214
215 When using the Visual C compiler, the second item is returned as
216 "-libpath:d:\mesalibs mesa.lib user32.lib".
217
218 When using the Borland compiler, the second item is returned as
219 "-Ld:\mesalibs mesa.lib user32.lib", and MakeMaker takes care of
220 moving the "-Ld:\mesalibs" to the correct place in the linker command
221 line.
222
224 ExtUtils::MakeMaker
225
226
227
228perl v5.36.0 2023-01-02 ExtUtils::Liblist(3)