blob: 254bd41f573b60e3e4f4636f2737dcf5222bdd29 [file] [log] [blame]
<html>
<head>
<title>SWIG:Examples:perl5</title>
</head>
<body bgcolor="#ffffff">
<H1>SWIG Perl Examples</H1>
<p>
The following examples illustrate the use of SWIG with Perl.
<ul>
<li><a href="simple/index.html">simple</a>. A minimal example showing how SWIG can
be used to wrap a C function and a global variable.
<li><a href="constants/index.html">constants</a>. This shows how preprocessor macros and
certain C declarations are turned into constants.
<li><a href="variables/index.html">variables</a>. This example shows how to access C global variables from Perl.
<li><a href="value/index.html">value</a>. How to pass and return structures by value.
<li><a href="class/index.html">class</a>. How to wrap a simple C++ class.
<li><a href="reference/index.html">reference</a>. C++ references.
<li><a href="pointer/index.html">pointer</a>. Simple pointer handling.
<li><a href="funcptr/index.html">funcptr</a>. Pointers to functions.
</ul>
<h2>Compilation Issues</h2>
<ul>
<li>To create a Perl extension, SWIG is run with the following options:
<blockquote>
<pre>
% swig -perl5 interface.i
</pre>
</blockquote>
<li>The compilation of examples is done using the file <tt>Example/Makefile</tt>. This
makefile performs a manual module compilation which is platform specific. Typically,
the steps look like this (Linux):
<blockquote>
<pre>
% swig -perl5 interface.i
% gcc -fpic -c -Dbool=char -I/usr/lib/perl5/5.00503/i386-linux/CORE interface_wrap.c
% gcc -shared interface_wrap.o $(OBJS) -o interface.so
% perl
use interface;
...
</pre>
</blockquote>
<li>The politically "correct" way to compile a Perl extension module is to use MakeMaker
and related tools (especially if you are considering third-party distribution). Consult
a book such as Advanced Perl Programming for details.
</ul>
<h2>Compatibility</h2>
The examples have been extensively tested on the following platforms:
<p>
<ul>
<li>Linux
<li>Solaris
</ul>
Please see the <a href="../../Doc/Manual/Windows.html">Windows</a> page in the main manual for information on using the examples on Windows. <p>
The most recent version of Perl used for testing is as follows:
<blockquote>
<pre>
% perl -version
This is perl, v5.6.0 built for sun4-solaris
Copyright 1987-2000, Larry Wall
Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5.0 source kit.
Complete documentation for Perl, including FAQ lists, should be found on
this system using `man perl' or `perldoc perl'. If you have access to the
Internet, point your browser at http://www.perl.com/, the Perl Home Page.
</pre>
</blockquote>
<p>
Due to wide variations in the Perl C API and differences between versions such as the ActivePerl release for Windows,
the code generated by SWIG is extremely messy. We have made every attempt to maintain compatibility with
many Perl releases going as far back as 5.003 and as recent as 5.6. However, your mileage may vary.
If you experience a problem, please let us know by
contacting us on the <a href="http://www.swig.org/mail.html">mailing lists</a>.
Better yet, send us a patch.
</body>
</html>