perlembed.html
来自「perl教程」· HTML 代码 · 共 795 行 · 第 1/5 页
HTML
795 行
<?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>perlembed - how to embed perl in your C program</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>perlembed - how to embed perl in your C program</a></h1>
<p><a name="__index__"></a></p>
<!-- INDEX BEGIN -->
<ul>
<li><a href="#name">NAME</a></li>
<li><a href="#description">DESCRIPTION</a></li>
<ul>
<li><a href="#preamble">PREAMBLE</a></li>
<li><a href="#roadmap">ROADMAP</a></li>
<li><a href="#compiling_your_c_program">Compiling your C program</a></li>
<li><a href="#adding_a_perl_interpreter_to_your_c_program">Adding a Perl interpreter to your C program</a></li>
<li><a href="#calling_a_perl_subroutine_from_your_c_program">Calling a Perl subroutine from your C program</a></li>
<li><a href="#evaluating_a_perl_statement_from_your_c_program">Evaluating a Perl statement from your C program</a></li>
<li><a href="#performing_perl_pattern_matches_and_substitutions_from_your_c_program">Performing Perl pattern matches and substitutions from your C program</a></li>
<li><a href="#fiddling_with_the_perl_stack_from_your_c_program">Fiddling with the Perl stack from your C program</a></li>
<li><a href="#maintaining_a_persistent_interpreter">Maintaining a persistent interpreter</a></li>
<li><a href="#execution_of_end_blocks">Execution of END blocks</a></li>
<li><a href="#maintaining_multiple_interpreter_instances">Maintaining multiple interpreter instances</a></li>
<li><a href="#using_perl_modules__which_themselves_use_c_libraries__from_your_c_program">Using Perl modules, which themselves use C libraries, from your C program</a></li>
</ul>
<li><a href="#embedding_perl_under_win32">Embedding Perl under Win32</a></li>
<li><a href="#hiding_perl_">Hiding Perl_</a></li>
<li><a href="#moral">MORAL</a></li>
<li><a href="#author">AUTHOR</a></li>
<li><a href="#copyright">COPYRIGHT</a></li>
</ul>
<!-- INDEX END -->
<hr />
<p>
</p>
<h1><a name="name">NAME</a></h1>
<p>perlembed - how to embed perl in your C program</p>
<p>
</p>
<hr />
<h1><a name="description">DESCRIPTION</a></h1>
<p>
</p>
<h2><a name="preamble">PREAMBLE</a></h2>
<p>Do you want to:</p>
<dl>
<dt><strong><a name="item_use_c_from_perl_3f"><strong>Use C from Perl?</strong></a></strong>
<dd>
<p>Read <a href="../../lib/Pod/perlxstut.html">the perlxstut manpage</a>, <a href="../../lib/Pod/perlxs.html">the perlxs manpage</a>, <em>h2xs</em>, <a href="../../lib/Pod/perlguts.html">the perlguts manpage</a>, and <a href="../../lib/Pod/perlapi.html">the perlapi manpage</a>.</p>
</dd>
</li>
<dt><strong><a name="item_use_a_unix_program_from_perl_3f"><strong>Use a Unix program from Perl?</strong></a></strong>
<dd>
<p>Read about back-quotes and about <a href="../../lib/Pod/perlfunc.html#item_system"><code>system</code></a> and <a href="../../lib/Pod/perlfunc.html#item_exec"><code>exec</code></a> in <a href="../../lib/Pod/perlfunc.html">the perlfunc manpage</a>.</p>
</dd>
</li>
<dt><strong><a name="item_use_perl_from_perl_3f"><strong>Use Perl from Perl?</strong></a></strong>
<dd>
<p>Read about <a href="../../lib/Pod/perlfunc.html#do">do in the perlfunc manpage</a> and <a href="../../lib/Pod/perlfunc.html#eval">eval in the perlfunc manpage</a> and <a href="../../lib/Pod/perlfunc.html#require">require in the perlfunc manpage</a>
and <a href="../../lib/Pod/perlfunc.html#use">use in the perlfunc manpage</a>.</p>
</dd>
</li>
<dt><strong><a name="item_use_c_from_c_3f"><strong>Use C from C?</strong></a></strong>
<dd>
<p>Rethink your design.</p>
</dd>
</li>
<dt><strong><a name="item_use_perl_from_c_3f"><strong>Use Perl from C?</strong></a></strong>
<dd>
<p>Read on...</p>
</dd>
</li>
</dl>
<p>
</p>
<h2><a name="roadmap">ROADMAP</a></h2>
<ul>
<li>
<p>Compiling your C program</p>
</li>
<li>
<p>Adding a Perl interpreter to your C program</p>
</li>
<li>
<p>Calling a Perl subroutine from your C program</p>
</li>
<li>
<p>Evaluating a Perl statement from your C program</p>
</li>
<li>
<p>Performing Perl pattern matches and substitutions from your C program</p>
</li>
<li>
<p>Fiddling with the Perl stack from your C program</p>
</li>
<li>
<p>Maintaining a persistent interpreter</p>
</li>
<li>
<p>Maintaining multiple interpreter instances</p>
</li>
<li>
<p>Using Perl modules, which themselves use C libraries, from your C program</p>
</li>
<li>
<p>Embedding Perl under Win32</p>
</li>
</ul>
<p>
</p>
<h2><a name="compiling_your_c_program">Compiling your C program</a></h2>
<p>If you have trouble compiling the scripts in this documentation,
you're not alone. The cardinal rule: COMPILE THE PROGRAMS IN EXACTLY
THE SAME WAY THAT YOUR PERL WAS COMPILED. (Sorry for yelling.)</p>
<p>Also, every C program that uses Perl must link in the <em>perl library</em>.
What's that, you ask? Perl is itself written in C; the perl library
is the collection of compiled C programs that were used to create your
perl executable (<em>/usr/bin/perl</em> or equivalent). (Corollary: you
can't use Perl from your C program unless Perl has been compiled on
your machine, or installed properly--that's why you shouldn't blithely
copy Perl executables from machine to machine without also copying the
<em>lib</em> directory.)</p>
<p>When you use Perl from C, your C program will--usually--allocate,
"run", and deallocate a <em>PerlInterpreter</em> object, which is defined by
the perl library.</p>
<p>If your copy of Perl is recent enough to contain this documentation
(version 5.002 or later), then the perl library (and <em>EXTERN.h</em> and
<em>perl.h</em>, which you'll also need) will reside in a directory
that looks like this:</p>
<pre>
/usr/local/lib/perl5/your_architecture_here/CORE</pre>
<p>or perhaps just</p>
<pre>
/usr/local/lib/perl5/CORE</pre>
<p>or maybe something like</p>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?