相对于传统的C调用(见 http://www.linuxidc.com/Linux/2012-02/55037.htm),使用ctype实在是太简单了编写一个动态链接库ctype_test.c,
- #include <stdlib.h>
-
- int foo(int a, int b)
- {
- printf("Your input %i and %i
", 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)