dynaloader.html

来自「perl教程」· HTML 代码 · 共 545 行 · 第 1/2 页

HTML
545
字号
<?xml version="1.0" ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<!-- saved from url=(0017)http://localhost/ -->
<script language="JavaScript" src="../displayToc.js"></script>
<script language="JavaScript" src="../tocParas.js"></script>
<script language="JavaScript" src="../tocTab.js"></script>
<link rel="stylesheet" type="text/css" href="../scineplex.css">
<title>DynaLoader - Dynamically load C libraries into Perl code</title>
<link rel="stylesheet" href="../Active.css" type="text/css" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rev="made" href="mailto:" />
</head>

<body>

<script>writelinks('__top__',1);</script>
<h1><a>DynaLoader - Dynamically load C libraries into Perl code</a></h1>
<p><a name="__index__"></a></p>

<!-- INDEX BEGIN -->

<ul>

	<li><a href="#name">NAME</a></li>
	<li><a href="#synopsis">SYNOPSIS</a></li>
	<li><a href="#description">DESCRIPTION</a></li>
	<li><a href="#author">AUTHOR</a></li>
</ul>
<!-- INDEX END -->

<hr />
<p>
</p>
<h1><a name="name">NAME</a></h1>
<p>DynaLoader - Dynamically load C libraries into Perl code</p>
<p>
</p>
<hr />
<h1><a name="synopsis">SYNOPSIS</a></h1>
<pre>
    <span class="keyword">package</span> <span class="variable">YourPackage</span><span class="operator">;</span>
    <span class="keyword">require</span> <span class="variable">DynaLoader</span><span class="operator">;</span>
    <span class="variable">@ISA</span> <span class="operator">=</span> <span class="string">qw(... DynaLoader ...)</span><span class="operator">;</span>
    <span class="variable">bootstrap</span> <span class="variable">YourPackage</span><span class="operator">;</span>
</pre>
<pre>
    <span class="comment"># optional method for 'global' loading</span>
    <span class="keyword">sub</span><span class="variable"> dl_load_flags </span><span class="operator">{</span> <span class="number">0x01</span> <span class="operator">}</span>
</pre>
<p>
</p>
<hr />
<h1><a name="description">DESCRIPTION</a></h1>
<p>This document defines a standard generic interface to the dynamic
linking mechanisms available on many platforms.  Its primary purpose is
to implement automatic dynamic loading of Perl modules.</p>
<p>This document serves as both a specification for anyone wishing to
implement the DynaLoader for a new platform and as a guide for
anyone wishing to use the DynaLoader directly in an application.</p>
<p>The DynaLoader is designed to be a very simple high-level
interface that is sufficiently general to cover the requirements
of SunOS, HP-UX, NeXT, Linux, VMS and other platforms.</p>
<p>It is also hoped that the interface will cover the needs of OS/2, NT
etc and also allow pseudo-dynamic linking (using <code>ld -A</code> at runtime).</p>
<p>It must be stressed that the DynaLoader, by itself, is practically
useless for accessing non-Perl libraries because it provides almost no
Perl-to-C 'glue'.  There is, for example, no mechanism for calling a C
library function or supplying arguments.  A C::DynaLib module
is available from CPAN sites which performs that function for some
common system types.  And since the year 2000, there's also Inline::C,
a module that allows you to write Perl subroutines in C.  Also available
from your local CPAN site.</p>
<p>DynaLoader Interface Summary</p>
<pre>
  @dl_library_path
  @dl_resolve_using
  @dl_require_symbols
  $dl_debug
  @dl_librefs
  @dl_modules
  @dl_shared_objects
                                                  Implemented in:
  bootstrap($modulename)                               Perl
  @filepaths = dl_findfile(@names)                     Perl
  $flags = $modulename-&gt;dl_load_flags                  Perl
  $symref  = dl_find_symbol_anywhere($symbol)          Perl</pre>
<pre>
  $libref  = dl_load_file($filename, $flags)           C
  $status  = dl_unload_file($libref)                   C
  $symref  = dl_find_symbol($libref, $symbol)          C
  @symbols = dl_undef_symbols()                        C
  dl_install_xsub($name, $symref [, $filename])        C
  $message = dl_error                                  C</pre>
<dl>
<dt><strong><a name="item__dl_library_path">@dl_library_path</a></strong>

<dd>
<p>The standard/default list of directories in which <a href="#item_dl_findfile"><code>dl_findfile()</code></a> will
search for libraries etc.  Directories are searched in order:
$dl_library_path[0], [1], ... etc</p>
</dd>
<dd>
<p>@dl_library_path is initialised to hold the list of 'normal' directories
(<em>/usr/lib</em>, etc) determined by <strong>Configure</strong> (<code>$Config{'libpth'}</code>).  This should
ensure portability across a wide range of platforms.</p>
</dd>
<dd>
<p>@dl_library_path should also be initialised with any other directories
that can be determined from the environment at runtime (such as
LD_LIBRARY_PATH for SunOS).</p>
</dd>
<dd>
<p>After initialisation @dl_library_path can be manipulated by an
application using push and unshift before calling dl_findfile().
Unshift can be used to add directories to the front of the search order
either to save search time or to override libraries with the same name
in the 'normal' directories.</p>
</dd>
<dd>
<p>The load function that <a href="#item_dl_load_file"><code>dl_load_file()</code></a> calls may require an absolute
pathname.  The <a href="#item_dl_findfile"><code>dl_findfile()</code></a> function and @dl_library_path can be
used to search for and return the absolute pathname for the
library/object that you wish to load.</p>
</dd>
</li>
<dt><strong><a name="item__dl_resolve_using">@dl_resolve_using</a></strong>

<dd>
<p>A list of additional libraries or other shared objects which can be
used to resolve any undefined symbols that might be generated by a
later call to load_file().</p>
</dd>
<dd>
<p>This is only required on some platforms which do not handle dependent
libraries automatically.  For example the Socket Perl extension
library (<em>auto/Socket/Socket.so</em>) contains references to many socket
functions which need to be resolved when it's loaded.  Most platforms
will automatically know where to find the 'dependent' library (e.g.,
<em>/usr/lib/libsocket.so</em>).  A few platforms need to be told the
location of the dependent library explicitly.  Use @dl_resolve_using
for this.</p>
</dd>
<dd>
<p>Example usage:</p>
</dd>
<dd>
<pre>
    <span class="variable">@dl_resolve_using</span> <span class="operator">=</span> <span class="variable">dl_findfile</span><span class="operator">(</span><span class="string">'-lsocket'</span><span class="operator">);</span>
</pre>
</dd>
</li>
<dt><strong><a name="item__dl_require_symbols">@dl_require_symbols</a></strong>

<dd>
<p>A list of one or more symbol names that are in the library/object file
to be dynamically loaded.  This is only required on some platforms.</p>
</dd>
</li>
<dt><strong><a name="item__dl_librefs">@dl_librefs</a></strong>

<dd>
<p>An array of the handles returned by successful calls to dl_load_file(),
made by bootstrap, in the order in which they were loaded.
Can be used with <a href="#item_dl_find_symbol"><code>dl_find_symbol()</code></a> to look for a symbol in any of
the loaded files.</p>
</dd>
</li>
<dt><strong><a name="item__dl_modules">@dl_modules</a></strong>

<dd>
<p>An array of module (package) names that have been bootstrap'ed.</p>
</dd>
</li>
<dt><strong><a name="item__dl_shared_objects">@dl_shared_objects</a></strong>

<dd>
<p>An array of file names for the shared objects that were loaded.</p>
</dd>
</li>
<dt><strong><a name="item_dl_error"><code>dl_error()</code></a></strong>

<dd>
<p>Syntax:</p>
</dd>
<dd>
<pre>
    <span class="variable">$message</span> <span class="operator">=</span> <span class="variable">dl_error</span><span class="operator">();</span>
</pre>
</dd>
<dd>
<p>Error message text from the last failed DynaLoader function.  Note
that, similar to errno in unix, a successful function call does not
reset this message.</p>
</dd>
<dd>
<p>Implementations should detect the error as soon as it occurs in any of
the other functions and save the corresponding message for later
retrieval.  This will avoid problems on some platforms (such as SunOS)
where the error message is very temporary (e.g., dlerror()).</p>
</dd>
</li>
<dt><strong><a name="item__dl_debug">$dl_debug</a></strong>

<dd>
<p>Internal debugging messages are enabled when $dl_debug is set true.
Currently setting $dl_debug only affects the Perl side of the
DynaLoader.  These messages should help an application developer to
resolve any DynaLoader usage problems.</p>
</dd>
<dd>
<p>$dl_debug is set to <code>$ENV{'PERL_DL_DEBUG'}</code> if defined.</p>
</dd>
<dd>
<p>For the DynaLoader developer/porter there is a similar debugging
variable added to the C code (see dlutils.c) and enabled if Perl was
built with the <strong>-DDEBUGGING</strong> flag.  This can also be set via the
PERL_DL_DEBUG environment variable.  Set to 1 for minimal information or
higher for more.</p>
</dd>
</li>
<dt><strong><a name="item_dl_findfile"><code>dl_findfile()</code></a></strong>

<dd>
<p>Syntax:</p>
</dd>
<dd>
<pre>
    @filepaths = dl_findfile(@names)</pre>
</dd>
<dd>
<p>Determine the full paths (including file suffix) of one or more
loadable files given their generic names and optionally one or more
directories.  Searches directories in @dl_library_path by default and
returns an empty list if no files were found.</p>
</dd>
<dd>
<p>Names can be specified in a variety of platform independent forms.  Any
names in the form <strong>-lname</strong> are converted into <em>libname.*</em>, where <em>.*</em> is
an appropriate suffix for the platform.</p>
</dd>
<dd>
<p>If a name does not already have a suitable prefix and/or suffix then
the corresponding file will be searched for by trying combinations of
prefix and suffix appropriate to the platform: &quot;$name.o&quot;, &quot;lib$name.*&quot;
and &quot;$name&quot;.</p>
</dd>
<dd>
<p>If any directories are included in @names they are searched before
@dl_library_path.  Directories may be specified as <strong>-Ldir</strong>.  Any other
names are treated as filenames to be searched for.</p>
</dd>
<dd>
<p>Using arguments of the form <code>-Ldir</code> and <code>-lname</code> is recommended.</p>
</dd>
<dd>
<p>Example:</p>
</dd>
<dd>
<pre>
    <span class="variable">@dl_resolve_using</span> <span class="operator">=</span> <span class="variable">dl_findfile</span><span class="operator">(</span><span class="string">qw(-L/usr/5lib -lposix)</span><span class="operator">);</span>
</pre>
</dd>
</li>
<dt><strong><a name="item_dl_expandspec"><code>dl_expandspec()</code></a></strong>

<dd>
<p>Syntax:</p>
</dd>
<dd>
<pre>
    $filepath = dl_expandspec($spec)</pre>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?