SWIG Perl Examples
$Header: /cvs/projects/SWIG/Examples/perl5/index.html,v 1.1 2000/06/17 23:46:21 beazley Exp $
The following examples illustrate the use of SWIG with Perl.
- simple. A minimal example showing how SWIG can
be used to wrap a C function and a global variable.
- constants. This shows how preprocessor macros and
certain C declarations are turned into constants.
Compilation Issues
- To create a Perl extension, SWIG is run with the following options:
% swig -perl5 interface.i
- The compilation of examples is done using the file Example/Makefile. 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 interface.so
% perl
use interface;
...
- 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.
Compatibility
The examples have been extensively tested on the following platforms:
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
sending a message to swig-dev@cs.uchicago.edu.
Better yet, send us a patch.