①创建一个有一些函数的C语言文件
cfun.c
int product(int a, int b) { return a * b; }
②编译它并创建共享的库文件
gcc -o hxxlib.so --shared -fPIC cfun.c
③在python文件中使用生成的共享库文件
from ctypes import * c_file = 'hxxlib.so' c_fun = CDLL(c_file) a = 2 b = 5 print(c_fun.product(a,b))
①创建一个有一些函数的C语言文件
cfun.c
int product(int a, int b) { return a * b; }
②编译它并创建共享的库文件
gcc -o hxxlib.so --shared -fPIC cfun.c
③在python文件中使用生成的共享库文件
from ctypes import * c_file = 'hxxlib.so' c_fun = CDLL(c_file) a = 2 b = 5 print(c_fun.product(a,b))