swig c python
2014-02-19 17:02
316 查看
http://www.swig.org/translations/chinese/tutorial.html
swig -python example.i
xsheng@bcxcp-AS-dev01:~/workspace/swig$ gcc -fpic -c example.c example_wrap.c -I /home/ezhao/tools/python-2.7/include/python2.7/
xsheng@bcxcp-AS-dev01:~/workspace/swig$ ld -shared example.o example_wrap.o -o _example.so
/* File : example.c */ #include <time.h> double My_variable = 3.0; int fact(int n) { if (n <= 1) return 1; else return n*fact(n-1); } int my_mod(int x, int y) { return (x%y); } char *get_time() { time_t ltime; time(<ime); return ctime(<ime); }
/* example.i */ %module example %{ /* Put header files here or function declarations like below */ extern double My_variable; extern int fact(int n); extern int my_mod(int x, int y); extern char *get_time(); %} extern double My_variable; extern int fact(int n); extern int my_mod(int x, int y); extern char *get_time();
swig -python example.i
xsheng@bcxcp-AS-dev01:~/workspace/swig$ gcc -fpic -c example.c example_wrap.c -I /home/ezhao/tools/python-2.7/include/python2.7/
xsheng@bcxcp-AS-dev01:~/workspace/swig$ ld -shared example.o example_wrap.o -o _example.so
现在可以使用如下Python模块 :
>>> import example >>> example.fact(5) 120 >>> example.my_mod(7,3) 1 >>> example.get_time() 'Sun Feb 11 23:01:07 1996' >>>
相关文章推荐
- fatal error: Python.h: No such file or directory
- Python:itertools模块 combinations和product的使用
- 整理:python的二维数组操作
- 纯python处理时区的转换
- Python小记(1):断言与异常
- python的时区处理
- python 实现全排列
- python的pip和virtualenv使用心得
- 使用镜像服务器加速你的Python PyPi
- python unittest框架用后分享
- 很浅浅的谈谈 python doctest
- 批量修改图形文件的对比度和锐度,python 2.7
- Python模块学习 ---- datetime
- Python3 入门(二)
- Python Django Web 框架,从安装到完成 Web 站点的设计
- Python3 入门(一)
- 时间比较
- python - easy_install的安装和使用
- Python的包管理工具
- Python线性时间排序——桶排序、基数排序与计数排序