Python使用ctype调用C链接库
Python使用ctype调用C链接库
相对于传统的C调用(见 ),使用ctype实在是太简单了
编写一个动态链接库ctype_test.c,
- #include <stdlib.h>
- int foo(int a, int b)
- {
- printf("Your input %i and %i\n", a, b);
- return a + b;
- }
编译
gcc -o ctype.so -shared -fPIC ctype_test.c
在python下试用一下吧
- import ctypes
- ll = ctypes.cdll.LoadLibrary # 我这是在linux下,windows调用windll之类的
- lib = ll("./ctype.so")
- lib.foo(1, 3)
评论暂时关闭