blob: 23c8ff658139e451277321607e467203da84cc6a [file] [log] [blame]
<body bgcolor="#ffffff">
<H1>SWIG Perl Examples</H1>
The following examples illustrate the use of SWIG with Perl.
<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.
<li><a href="callback/index.html">callback</a>. C++ callbacks using directors.
<li><a href="extend/index.html">extend</a>. Extending a simple C++ class.
<h2>Compilation Issues</h2>
<li>To create a Perl extension, SWIG is run with the following options:
% swig -perl5 interface.i
<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):
% 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
% perl
use interface;
<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.
The examples have been extensively tested on the following platforms:
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>
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.
If the code doesn't compile or work with your version of Perl, please let us know by
contacting us on the <a href="">mailing lists</a>.
Better yet, send us a patch.