XXX.so的源码为C语言,编译时依赖libusb1.0.so。
在python脚本 test.py打开该库时报错。
import ctypes
libc = ctypes.CDLL('XXX.so')
Traceback (most recent call last):
File "test.py", line 80, in <module>
ReadData()
File "test.py", line 20, in ReadData
libc = ctypes.CDLL('XXX.so')
File "/usr/lib/python3.6/ctypes/__init__.py", line 348, in __init__
self._handle = _dlopen(self._name, mode)
OSError: XXX.so: undefined symbol: libusb_open
解决办法:
在libc = ctypes.CDLL('XXX.so')之前,加入:ctypes.CDLL('libusb-1.0.so',ctypes.RTLD_GLOBAL)
import ctypes
ctypes.CDLL('libusb-1.0.so',ctypes.RTLD_GLOBAL)
libc = ctypes.CDLL('XXX.so')