I have a binary file that can load .soshared objects to extend functionality. These extensions are encoded in C ++, but I want to use some pre-encoded python functions, so I use the Python C API . So far so good.
Calling Python functions works well, but if I import the spidev module in Python , I get the following error:
import spidev
ImportError: /usr/local/lib/python2.7/dist-packages/spidev.so: undefined symbol: _Py_ZeroStruct
Segmentation fault
If I import the standard python modules (sys, os, argparse ...), there is no problem.
What could be the problem?
NB: I know that I could use spidev directly from C ++, but I wanted to use the existing python code as much as possible.
UPDATE:
As @BrianCain and @qarma pointed out, this could be a dependency problem libpython, so I include the outputs ldd:
$ ldd myextension.so
/usr/lib/arm-linux-gnueabihf/libcofi_rpi.so (0xb6f89000)
libpthread.so.0 => /lib/arm-linux-gnueabihf/libpthread.so.0 (0xb6f5f000)
libdl.so.2 => /lib/arm-linux-gnueabihf/libdl.so.2 (0xb6f54000)
libutil.so.1 => /lib/arm-linux-gnueabihf/libutil.so.1 (0xb6f49000)
libm.so.6 => /lib/arm-linux-gnueabihf/libm.so.6 (0xb6ed8000)
libpython2.7.so.1.0 => /usr/lib/libpython2.7.so.1.0 (0xb6c47000)
libgcc_s.so.1 => /lib/arm-linux-gnueabihf/libgcc_s.so.1 (0xb6c1f000)
libc.so.6 => /lib/arm-linux-gnueabihf/libc.so.6 (0xb6af0000)
/lib/ld-linux-armhf.so.3 (0xb6fa2000)
libz.so.1 => /lib/arm-linux-gnueabihf/libz.so.1 (0xb6ad2000)
$ ldd /usr/local/lib/python2.7/dist-packages/spidev.so
/usr/lib/arm-linux-gnueabihf/libcofi_rpi.so (0xb6ed3000)
libpthread.so.0 => /lib/arm-linux-gnueabihf/libpthread.so.0 (0xb6ea9000)
libc.so.6 => /lib/arm-linux-gnueabihf/libc.so.6 (0xb6d7a000)
/lib/ld-linux-armhf.so.3 (0xb6eed000)
UPDATE2:
The output of the spidev installation.
$ sudo pip install spidev
Downloading/unpacking spidev
Downloading spidev-2.0.tar.gz
Running setup.py egg_info for package spidev
Installing collected packages: spidev
Running setup.py install for spidev
building 'spidev' extension
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/src/linux/include -I/usr/include/python2.7 -c spidev_module.c -o build/temp.linux-armv6l-2.7/spidev_module.o
gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-z,relro build/temp.linux-armv6l-2.7/spidev_module.o -o build/lib.linux-armv6l-2.7/spidev.so
Successfully installed spidev
Cleaning up...
$ ldd /usr/local/lib/python2.7/dist-packages/spidev.so
/usr/lib/arm-linux-gnueabihf/libcofi_rpi.so (0xb6f97000)
libpthread.so.0 => /lib/arm-linux-gnueabihf/libpthread.so.0 (0xb6f6d000)
libc.so.6 => /lib/arm-linux-gnueabihf/libc.so.6 (0xb6e3e000)
/lib/ld-linux-armhf.so.3 (0xb6fb1000)
Still independent of libpython...