This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

SWIG, What switches/flags are required to make SWIG work?


Hello,

I am trying to get the first example out of the SWIG tutorial (www.swig.org) to work,
and it does not for me. Before I rush into my code. I am able to make neither a
Python nor Perl example to work. I tried downloading SWIG from www.swig.org
onto Cygwin and that did not work, although the same downloaded sources did
work for RH/SUSE. I was able to get the example working for RH and SUSE
Linux. I suspect that it is a matter of some compile switch. If compilation flags
would it be appropriate to document them in the FAQ, API?


BTW I had to create an example.h file for inclusion into the example.i file; this step is
not present in the SWIG tutorial, but at least I was able to resolve that.


When I run my example test program, I get :-

$ test_example.pl
Can't load './example.dll' for module example: Bad address at /usr/lib/perl5/5.8/cygwin/DynaLoader.pm line 230.
at example.pm line 8
Compilation failed in require at ./test_example.pl line 3.
BEGIN failed--compilation aborted at ./test_example.pl line 3.
]0;/cygdrive/e/Share/Brian/MOS/Perl/Swig
Brian@home-PC /cygdrive/e/Share/Brian/MOS/Perl/Swig
$


When I go to the relevant line in the DynaLoader it says my module has failed to load, why?

DynaLoader.pm :--
   # Many dynamic extension loading problems will appear to come from
   # this section of code: XYZ failed at line 123 of DynaLoader.pm.
   # Often these errors are actually occurring in the initialisation
   # C code of the extension XS file. Perl reports the error as being
   # in this perl code simply because this was the last perl code
   # it executed.

   my $libref = dl_load_file($file, $module->dl_load_flags) or
croak("Can't load '$file' for module $module: ".dl_error());

########################
This is my build:-

rm -rf *.o *.a *.dll example_wrap.c example.pm
gcc -c -I/usr/lib/perl5/5.8/cygwin/CORE/ example.c
swig -perl5 example.i
gcc -c -I/usr/lib/perl5/5.8/cygwin/CORE/ example_wrap.c
ld -shared -o example.dll example.o xample_wrap.o -L/usr/lib/perl5/5.8/cygwin/CORE/ -lperl -lpthread -lm -lc


############
This is my example.i

/* File : example.i */
%module example
%{
/* Put headers and other declarations here */
#include "example.h"
%}

extern double My_variable;
extern int fact(int);
extern int my_mod(int n, int m);

#######################
This is my example.c

/* File : example.c */
#include "example.h"

double My_variable = 3.0;

/* Compute factorial of n */
int fact(int n)
{
 if (n <= 1) return 1;
 else return n*fact(n-1);
}

/* Compute n mod m */
int my_mod(int n, int m)
{
 return(n % m);
}

#########################
This is my example.h

extern double My_variable;
extern int fact(int);
extern int my_mod(int n, int m);

###########################
This is my Makefile

.SUFFICIES : .c .i .o

OBJS=example.o example_wrap.o
TARGET=example.dll

CCOPTS= -I/usr/lib/perl5/5.8/cygwin/CORE/
LDOPTS= -L/usr/lib/perl5/5.8/cygwin/CORE/ -lperl -lpthread -lm -lc
SWIGOPTS=-perl5
LD=ld
CC=gcc
SWIG=swig

all $(TARGET) : $(OBJS)
$(LD) -shared -o $(TARGET) $(OBJS) $(LDOPTS)

example_wrap.c : example.i
$(SWIG) $(SWIGOPTS) $<

clean :
rm -rf *.o *.a *.dll example_wrap.c example.pm

.c.o :
$(CC) -c $(CCOPTS) $<

#################################
This is my test_example.pl

#!/usr/bin/perl -w
use strict;
use example;
print example::fact(4), "\n";
print example::my_mod(23,7), "\n";
print $example::My_variable + 4.5, "\n";

#############################
I attach  cygcheck.out

#############################
Any help would be welcome.
Brian Woodroffe
brian_woodroffe@bigfoot.com


Attachment: cygcheck.out
Description: Binary data

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]