python call clib
touch 2 files in the same dir
1.c_func.c
1 #include <stdio.h> 2 3 int add(int a,int b) 4 { 5 printf("var1 = %d,var2 = %d\n",a,b); 6 7 return a + b; 8 }
gcc -o libc_func.so -shared -fPIC c_func.c
2.pycallc.py
1 #!/usr/bin/python3 2 3 import ctypes 4 5 loadLibrary = ctypes.cdll.LoadLibrary; 6 cLib = loadLibrary("./libc_func.so"); 7 ret = cLib.add(250 , 666); 8 print("res = %d"%ret);

浙公网安备 33010602011771号