with open ('math.c', 'w') as rsh:
rsh.write('''\
/**
* Sample function to call from Python 3
* Build:
* $ gcc -shared -o libmath.so -fPIC math.c
*
* See https://stackoverflow.com/a/14884166/4594973
*
**/
int add(int x, int y) {
return x + y;
}
''')
!gcc -shared -o libmath.so -fPIC math.c
from ctypes import *
_math = CDLL('./libmath.so') #change this to the path of "libcb.so" compiled file
_math.add.argtypes = (c_int, c_int)
print(_math.add(4,5))