/* File : example.c */
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);
}
/* File : example.i taken from the swig documentation */
%module example
%{
/* Put headers and other declarations here */
extern double My_variable;
extern int fact(int);
extern int my_mod(int n, int m);
%}
extern double My_variable;
extern int fact(int);
extern int my_mod(int n, int m);
$ python Python 2.4.4 (#2, Oct 19 2006, 23:03:48) [GCC 4.1.2 20061007 (prerelease) (Debian 4.1.1-16)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>>
$ swig -python example.i $ gcc -c -fpic example.c example_wrap.c -I/usr/include/python2.4 $ gcc -shared example.o example_wrap.o -o _example.so
$ python Python 2.4.4 (#2, Oct 19 2006, 23:03:48) [GCC 4.1.2 20061007 (prerelease) (Debian 4.1.1-16)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import example >>> print example.fact(4) 24 >>> print example.my_mod(30,7) 2 >>>
This document was produced using groff-1.19.