Error "invalid ELF class" using ctypes

after changing the installation from 32 to 64Bit Ubuntu my code is python+ctypes+c99broken. I have so far read that the error ./libfoo.so: wrong ELF class: ELFCLASS32means that my libfoo.so[1] is a 32-bit library and that python wants a version with a 64-bit version. How to report gcc/ctypesto create a 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.sowithgcc -c -std=c99 -lm -D_GNU_SOURCE -Wall -pedantic -fopenmp -ofoo.o foo.c

+3
source share
3 answers

You need to compile the object file as 64-bit and position-independent, and then link the object file to a shared library with 64-bit options. Sort of:

gcc -c -fPIC -m64 -std=c99 -lm -D_GNU_SOURCE -Wall -pedantic -fopenmp -o foo.o foo.c
gcc -m64 -shared -Wl,-soname,libfoo.so -o libfoo.so foo.o

64- gnu, . , - toolchain Python.

+3

-m64 gcc , , , 64- .

0

Reinstall cryptography.

This is how I solved this problem.

http://www.amk.ca/python/code/crypto.html

-1
source

All Articles