`

swig-python初试

 
阅读更多

swig不做介绍,python更不做介绍,自己去网上搜吧

linxu下安装swig需要的源码包在这里下   http://sourceforge.net/

笔者下到的:

wget "http://sourceforge.net/settings/mirror_choices?projectname=pcre&filename=pcre/8.12/pcre-8.12.zip" -O pcre-8.12.zip

wget http://sourceforge.net/projects/swig/files/swigwin/swigwin-2.0.4/swigwin-2.0.4.zip -O swigwin-2.0.4.zip

安装步骤

1.unzip这哥俩

2.先装pcre,进入pcre-8.12目录 ./configure ./make ./make install

3.再装swig,进入swigwin-2.0.4目录 ./configure ./make ./make install

4.小试一下,进入 swigwin-2.0.4/Examples/python/simple,make生成example.py _example.so

这里做必要的解释:

simple目录下有Makefile  example.c【C源码】 example.i【Interface定义】

example.c

/* File : example.c */

/* A global variable */
double Foo = 3.0;

/* Compute the greatest common divisor of positive integers */
int gcd(int x, int y) {
  int g;
  g = y;
  while (x > 0) {
    g = x;
    x = y % x;
    y = g;
  }
  return g;
}

--------------------

example.i

/* File : example.i */
%module example

%inline %{
extern int    gcd(int x, int y);
extern double Foo;
%}

5.使用范例:

>>> import example
>>> example.gcd(13,10)
1
>>> example.gcd(3,12)
3
>>>

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics