I have the following C code. I am trying to call this function from Python using ctypes
:
int add ( int arr [])
{
printf("number %d \n",arr[0]);
arr[0]=1;
return arr[0];
}
I compiled this by using:
gcc -fpic -c test.c
gcc -shared -o test.so test.o
then put it in /usr/local/lib
.
Python call for this was:
from ctypes import *
lib = 'test.so'
dll = cdll.LoadLibrary(lib)
IntArray5 = c_int * 5
ia = IntArray5(5, 1, 7, 33, 99)
res = dll.add(ia)
print res
but I always get some big number like -1365200
.
I tried also:
dll.add.argtypes=POINTER(c_type_int)
but it does not work.