Results 1 to 2 of 2
Has anyone one successfully compiled a C shared object for Python 2.6 using Swig?
I've been trying but I keep getting this error when I try to import - "dynamic ...
- 08-18-2009 #1
Python and Swig
Has anyone one successfully compiled a C shared object for Python 2.6 using Swig?
I've been trying but I keep getting this error when I try to import - "dynamic module does not define init function (initarith)"
arith.c
Compile lines:Code:int add(int a, int b) { return a + b; }
swig -python -module arith arith.c
gcc -I/usr/include/python2.6 -fPIC -c arith.c arith_wrap.c
ld -shared -o arith.so arith.o arith_wrap.o
I tried several sites and tutorials but I always get the same error. So has anyone got this to work? Does anyone know what's wrong?...Thanks...Gerard4143
Does anyone know how to bring C code into Python? Any answer will be appreciated..Make mine Arch Linux
- 08-19-2009 #2
Got it working...Gerard4143
MyLibrary2.c
MyLibrary2.hCode:unsigned short getidt() { char ch1[(sizeof (unsigned short) + sizeof(void*))]; __asm__ __volatile__ ( "sidt %0\n\t" :"=m"(ch1) ); return *(unsigned short*)ch1; }
MyLibrary2.iCode:unsigned short getidt();
And finally the compile lines:Code:%module MyLibrary2 %{ #include "MyLibrary2.h" %} unsigned short getidt();
Start Python interrupterCode:swig -python MyLibrary2.i gcc -fPIC -c MyLibrary2.c gcc -fPIC -c -I/usr/include/python2.6 MyLibrary2_wrap.c gcc -shared MyLibrary.o MyLibrary2_wrap.o _MyLibrary2.so
import MyLibrary2
MyLibrary2.getidt()
And after those simple steps...it works.....Its too hot to be doing this...Gerard4143Make mine Arch Linux


Reply With Quote