after changing from a 32 to 64Bit Ubuntu installation my python+ctypes+c99 code is broken. I read so far, that the error ./libfoo.so: wrong ELF class: ELFCLASS32 means, that my libfoo.so[1] is a 32Bit library and that python wants a 64Bit version. How do I tell gcc/ctypes to generate the library as 32Bit?
Thanks for any feedback!
Error message:
File "foo.py", line 8, in <module>
autofoo=cdll.LoadLibrary("./libfoo.so")
File "/usr/lib/python2.6/ctypes/__init__.py", line 431, in LoadLibrary
return self._dlltype(name)
File "/usr/lib/python2.6/ctypes/__init__.py", line 353, in __init__
self._handle = _dlopen(self._name, mode)
OSError: ./libfoo.so: wrong ELF class: ELFCLASS32
[1] I compile libfoo.so with gcc -c -std=c99 -lm -D_GNU_SOURCE -Wall -pedantic -fopenmp -ofoo.o foo.c
You need to compile the object file as 64 bit and position independent, then link the object file to the shared library with 64 bit options. Something like:
That should get you a 64 bit library on any gnu toolchain I have used. If you are still getting errors, something might be broken in your toolchain or Python.