embed.html
来自「perl教程」· HTML 代码 · 共 340 行
HTML
340 行
<?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>ExtUtils::Embed - Utilities for embedding Perl in C/C++ applications</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__',2);</script>
<h1><a>ExtUtils::Embed - Utilities for embedding Perl in C/C++ applications</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="#_export">@EXPORT</a></li>
<li><a href="#functions">FUNCTIONS</a></li>
<li><a href="#examples">EXAMPLES</a></li>
<li><a href="#see_also">SEE ALSO</a></li>
<li><a href="#author">AUTHOR</a></li>
</ul>
<!-- INDEX END -->
<hr />
<p>
</p>
<h1><a name="name">NAME</a></h1>
<p>ExtUtils::Embed - Utilities for embedding Perl in C/C++ applications</p>
<p>
</p>
<hr />
<h1><a name="synopsis">SYNOPSIS</a></h1>
<pre>
perl -MExtUtils::Embed -e xsinit
perl -MExtUtils::Embed -e ccopts
perl -MExtUtils::Embed -e ldopts</pre>
<p>
</p>
<hr />
<h1><a name="description">DESCRIPTION</a></h1>
<p>ExtUtils::Embed provides utility functions for embedding a Perl interpreter
and extensions in your C/C++ applications.
Typically, an application <strong>Makefile</strong> will invoke ExtUtils::Embed
functions while building your application.</p>
<p>
</p>
<hr />
<h1><a name="_export">@EXPORT</a></h1>
<p>ExtUtils::Embed exports the following functions:</p>
<p>xsinit(), ldopts(), ccopts(), perl_inc(), ccflags(),
ccdlflags(), xsi_header(), xsi_protos(), <a href="#item_xsi_body"><code>xsi_body()</code></a></p>
<p>
</p>
<hr />
<h1><a name="functions">FUNCTIONS</a></h1>
<dl>
<dt><strong><a name="item_xsinit"><code>xsinit()</code></a></strong>
<dd>
<p>Generate C/C++ code for the XS initializer function.</p>
</dd>
<dd>
<p>When invoked as <code>`perl -MExtUtils::Embed -e xsinit --`</code>
the following options are recognized:</p>
</dd>
<dd>
<p><strong>-o</strong> <output filename> (Defaults to <strong>perlxsi.c</strong>)</p>
</dd>
<dd>
<p><strong>-o STDOUT</strong> will print to STDOUT.</p>
</dd>
<dd>
<p><strong>-std</strong> (Write code for extensions that are linked with the current Perl.)</p>
</dd>
<dd>
<p>Any additional arguments are expected to be names of modules
to generate code for.</p>
</dd>
<dd>
<p>When invoked with parameters the following are accepted and optional:</p>
</dd>
<dd>
<p><a href="#item_xsinit"><code>xsinit($filename,$std,[@modules])</code></a></p>
</dd>
<dd>
<p>Where,</p>
</dd>
<dd>
<p><strong>$filename</strong> is equivalent to the <strong>-o</strong> option.</p>
</dd>
<dd>
<p><strong>$std</strong> is boolean, equivalent to the <strong>-std</strong> option.</p>
</dd>
<dd>
<p><strong>[@modules]</strong> is an array ref, same as additional arguments mentioned above.</p>
</dd>
</li>
<dt><strong><a name="item_examples">Examples</a></strong>
<dd>
<pre>
perl -MExtUtils::Embed -e xsinit -- -o xsinit.c Socket</pre>
</dd>
<dd>
<p>This will generate code with an <strong>xs_init</strong> function that glues the perl <strong>Socket::bootstrap</strong> function
to the C <strong>boot_Socket</strong> function and writes it to a file named <em>xsinit.c</em>.</p>
</dd>
<dd>
<p>Note that <strong>DynaLoader</strong> is a special case where it must call <strong>boot_DynaLoader</strong> directly.</p>
</dd>
<dd>
<pre>
perl -MExtUtils::Embed -e xsinit</pre>
</dd>
<dd>
<p>This will generate code for linking with <strong>DynaLoader</strong> and
each static extension found in <strong>$Config{static_ext}</strong>.
The code is written to the default file name <strong>perlxsi.c</strong>.</p>
</dd>
<dd>
<pre>
perl -MExtUtils::Embed -e xsinit -- -o xsinit.c -std DBI DBD::Oracle</pre>
</dd>
<dd>
<p>Here, code is written for all the currently linked extensions along with code
for <strong>DBI</strong> and <strong>DBD::Oracle</strong>.</p>
</dd>
<dd>
<p>If you have a working <strong>DynaLoader</strong> then there is rarely any need to statically link in any
other extensions.</p>
</dd>
<dt><strong><a name="item_ldopts"><code>ldopts()</code></a></strong>
<dd>
<p>Output arguments for linking the Perl library and extensions to your
application.</p>
</dd>
<dd>
<p>When invoked as <code>`perl -MExtUtils::Embed -e ldopts --`</code>
the following options are recognized:</p>
</dd>
<dd>
<p><strong>-std</strong></p>
</dd>
<dd>
<p>Output arguments for linking the Perl library and any extensions linked
with the current Perl.</p>
</dd>
<dd>
<p><strong>-I</strong> <path1:path2></p>
</dd>
<dd>
<p>Search path for ModuleName.a archives.
Default path is <strong>@INC</strong>.
Library archives are expected to be found as
<strong>/some/path/auto/ModuleName/ModuleName.a</strong>
For example, when looking for <strong>Socket.a</strong> relative to a search path,
we should find <strong>auto/Socket/Socket.a</strong></p>
</dd>
<dd>
<p>When looking for <strong>DBD::Oracle</strong> relative to a search path,
we should find <strong>auto/DBD/Oracle/Oracle.a</strong></p>
</dd>
<dd>
<p>Keep in mind that you can always supply <strong>/my/own/path/ModuleName.a</strong>
as an additional linker argument.</p>
</dd>
<dd>
<p><strong>--</strong> <list of linker args></p>
</dd>
<dd>
<p>Additional linker arguments to be considered.</p>
</dd>
<dd>
<p>Any additional arguments found before the <strong>--</strong> token
are expected to be names of modules to generate code for.</p>
</dd>
<dd>
<p>When invoked with parameters the following are accepted and optional:</p>
</dd>
<dd>
<p><a href="#item_ldopts"><code>ldopts($std,[@modules],[@link_args],$path)</code></a></p>
</dd>
<dd>
<p>Where:</p>
</dd>
<dd>
<p><strong>$std</strong> is boolean, equivalent to the <strong>-std</strong> option.</p>
</dd>
<dd>
<p><strong>[@modules]</strong> is equivalent to additional arguments found before the <strong>--</strong> token.</p>
</dd>
<dd>
<p><strong>[@link_args]</strong> is equivalent to arguments found after the <strong>--</strong> token.</p>
</dd>
<dd>
<p><strong>$path</strong> is equivalent to the <strong>-I</strong> option.</p>
</dd>
<dd>
<p>In addition, when ldopts is called with parameters, it will return the argument string
rather than print it to STDOUT.</p>
</dd>
</li>
<dt><strong>Examples</strong>
<dd>
<pre>
perl -MExtUtils::Embed -e ldopts</pre>
</dd>
<dd>
<p>This will print arguments for linking with <strong>libperl.a</strong>, <strong>DynaLoader</strong> and
extensions found in <strong>$Config{static_ext}</strong>. This includes libraries
found in <strong>$Config{libs}</strong> and the first ModuleName.a library
for each extension that is found by searching <strong>@INC</strong> or the path
specified by the <strong>-I</strong> option.
In addition, when ModuleName.a is found, additional linker arguments
are picked up from the <strong>extralibs.ld</strong> file in the same directory.</p>
</dd>
<dd>
<pre>
perl -MExtUtils::Embed -e ldopts -- -std Socket</pre>
</dd>
<dd>
<p>This will do the same as the above example, along with printing additional arguments for linking with the <strong>Socket</strong> extension.</p>
</dd>
<dd>
<pre>
perl -MExtUtils::Embed -e ldopts -- DynaLoader</pre>
</dd>
<dd>
<p>This will print arguments for linking with just the <strong>DynaLoader</strong> extension
and <strong>libperl.a</strong>.</p>
</dd>
<dd>
<pre>
perl -MExtUtils::Embed -e ldopts -- -std Msql -- -L/usr/msql/lib -lmsql</pre>
</dd>
<dd>
<p>Any arguments after the second '--' token are additional linker
arguments that will be examined for potential conflict. If there is no
conflict, the additional arguments will be part of the output.</p>
</dd>
<dt><strong><a name="item_perl_inc"><code>perl_inc()</code></a></strong>
<dd>
<p>For including perl header files this function simply prints:</p>
</dd>
<dd>
<pre>
<span class="operator">-</span><span class="variable">I</span><span class="variable">$Config</span><span class="operator">{</span><span class="string">archlibexp</span><span class="operator">}</span><span class="operator">/</span><span class="keyword">CORE</span>
</pre>
</dd>
<dd>
<p>So, rather than having to say:</p>
</dd>
<dd>
<pre>
<span class="variable">perl</span> <span class="operator">-</span><span class="variable">MConfig</span> <span class="keyword">-e</span> <span class="string">'print "-I$Config{archlibexp}/CORE"'</span>
</pre>
</dd>
<dd>
<p>Just say:</p>
</dd>
<dd>
<pre>
perl -MExtUtils::Embed -e perl_inc</pre>
</dd>
</li>
<dt><strong><a name="item_ccflags">ccflags(), <code>ccdlflags()</code></a></strong>
<dd>
<p>These functions simply print $Config{ccflags} and $Config{ccdlflags}</p>
</dd>
</li>
<dt><strong><a name="item_ccopts"><code>ccopts()</code></a></strong>
<dd>
<p>This function combines perl_inc(), <a href="#item_ccflags"><code>ccflags()</code></a> and <code>ccdlflags()</code> into one.</p>
</dd>
</li>
<dt><strong><a name="item_xsi_header"><code>xsi_header()</code></a></strong>
<dd>
<p>This function simply returns a string defining the same <strong>EXTERN_C</strong> macro as
<strong>perlmain.c</strong> along with #including <strong>perl.h</strong> and <strong>EXTERN.h</strong>.</p>
</dd>
</li>
<dt><strong><a name="item_xsi_protos"><code>xsi_protos(@modules)</code></a></strong>
<dd>
<p>This function returns a string of <strong>boot_$ModuleName</strong> prototypes for each @modules.</p>
</dd>
</li>
<dt><strong><a name="item_xsi_body"><code>xsi_body(@modules)</code></a></strong>
<dd>
<p>This function returns a string of calls to <strong>newXS()</strong> that glue the module <strong>bootstrap</strong>
function to <strong>boot_ModuleName</strong> for each @modules.</p>
</dd>
<dd>
<p><strong>xsinit()</strong> uses the xsi_* functions to generate most of its code.</p>
</dd>
</li>
</dl>
<p>
</p>
<hr />
<h1><a name="examples">EXAMPLES</a></h1>
<p>For examples on how to use <strong>ExtUtils::Embed</strong> for building C/C++ applications
with embedded perl, see <a href="../../lib/Pod/perlembed.html">the perlembed manpage</a>.</p>
<p>
</p>
<hr />
<h1><a name="see_also">SEE ALSO</a></h1>
<p><a href="../../lib/Pod/perlembed.html">the perlembed manpage</a></p>
<p>
</p>
<hr />
<h1><a name="author">AUTHOR</a></h1>
<p>Doug MacEachern <<em><a href="mailto:dougm@osf.org">dougm@osf.org</a></em>></p>
<p>Based on ideas from Tim Bunce <<em><a href="mailto:Tim.Bunce@ig.co.uk">Tim.Bunce@ig.co.uk</a></em>> and
<strong>minimod.pl</strong> by Andreas Koenig <<em><a href="mailto:k@anna.in-berlin.de">k@anna.in-berlin.de</a></em>> and Tim Bunce.</p>
</body>
</html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?