C源码
factorial.c(计算阶乘)
#include<stdio.h>
int fact(int n)
{
if (n <= 1){
return 1;
}
else
return n * fact(n - 1);
}
编译
编译好后生成了factorial.so
gcc -o factorial.so -shared -fPIC factorial.c
python调用
from ctypes import *
dll = cdll.LoadLibrary('./factorial.so')
ret = dll.fact(4)
print(ret)