Is SWIG appropriate
David Cannings <lists <at> edeca.net>
2004-05-04 17:18:10 GMT
I am no great programmer in either C or Perl but am trying to convert a C
header file into a Perl module. I have one that was made by somebody
else using an old version of h2xs and old versions of the header files
but now want to update it and document it properly. The header files are
from the MTA Exim and I want to be able to call certain functions from
the C file from Perl.
I have tried using h2xs to convert the header file without success so have
given up trying to use it. Its behaviour isn't consistent with the
manual page and there are bugs in perlbug that are three years old
relating to my problems. I get no response from Perl mailing lists
either, because of this I found SWIG.
The defines a number of functions, an enum and some other variables such
as "extern uschar *message_id". I decided to start small and get one
method working so have created myself a file called LocalScan.i that
contains:
-- File: LocalScan.i --
%module LocalScan
%{
/* Includes the header in the wrapper code */
#include "local_scan.h"
%}
/* Parse the header file to generate wrappers */
extern void header_add(int, char *, ...);
-- End file --
The above was got from reading the tutorial on the website. I have copied
the declaration for header_add() straight from the .h file. I now run:
# swig -perl5 LocalScan.i
Which generates the files LocalScan_wrap.c and LocalScan.pm, so I run:
# gcc -c LocalScan_wrap.c local_scan.c -I/usr/lib/perl/5.8/CORE
-I../exim4-4.31/src
I link to the Exim sources as other files are included by local_scan.h. I
get the following errors however:
-- Errors --
In file included from /usr/lib/perl/5.8/CORE/op.h:484,
from /usr/lib/perl/5.8/CORE/perl.h:2346,
from LocalScan_wrap.c:237:
/usr/lib/perl/5.8/CORE/reentr.h:611: error: field `_crypt_struct' has
incomplete type
In file included from /usr/lib/perl/5.8/CORE/perl.h:3554,
from LocalScan_wrap.c:237:
/usr/lib/perl/5.8/CORE/proto.h:199: error: parse error before "off64_t"
/usr/lib/perl/5.8/CORE/proto.h:201: error: parse error before
"Perl_do_sysseek"
/usr/lib/perl/5.8/CORE/proto.h:201: error: parse error before "off64_t"
/usr/lib/perl/5.8/CORE/proto.h:201: warning: data definition has no type
or storage class
/usr/lib/perl/5.8/CORE/proto.h:202: error: parse error before
"Perl_do_tell"
/usr/lib/perl/5.8/CORE/proto.h:202: warning: data definition has no type
or storage class
/usr/lib/perl/5.8/CORE/proto.h:1307: error: parse error before
"Perl_PerlIO_tell"
/usr/lib/perl/5.8/CORE/proto.h:1307: warning: data definition has no type
or storage class
/usr/lib/perl/5.8/CORE/proto.h:1308: error: parse error before "off64_t"
In file included from local_scan.h:16,
from LocalScan_wrap.c:586:
../exim4-4.31/src/mytypes.h:17:1: warning: "FALSE" redefined
In file included from /usr/lib/perl/5.8/CORE/perl.h:1807,
from LocalScan_wrap.c:237:
/usr/lib/perl/5.8/CORE/handy.h:47:1: warning: this is the location of the
previous definition
In file included from local_scan.h:16,
from LocalScan_wrap.c:586:
../exim4-4.31/src/mytypes.h:18:1: warning: "TRUE" redefined
In file included from /usr/lib/perl/5.8/CORE/perl.h:1807,
from LocalScan_wrap.c:237:
/usr/lib/perl/5.8/CORE/handy.h:46:1: warning: this is the location of the
previous definition
-- End errors --
Am I going about this the right way or can SWIG not do what I suggest? Is
it possible to fix the above? They seem to be errors with the Perl
sources as opposed to SWIG or Exim.
My apologies for the lengthly mail,
David
_______________________________________________
Swig maillist - Swig <at> cs.uchicago.edu
http://mailman.cs.uchicago.edu/mailman/listinfo/swig