so 文件信息
# readelf -h libencrypt.so ELF Header: Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 Class: ELF32 Data: 2's complement, little endian Version: 1 (current) OS/ABI: UNIX - System V ABI Version: 0 Type: DYN (Shared object file) Machine: ARM Version: 0x1 Entry point address: 0x0 Start of program headers: 52 (bytes into file) Start of section headers: 16768 (bytes into file) Flags: 0x5000000, Version5 EABI Size of this header: 52 (bytes) Size of program headers: 32 (bytes) Number of program headers: 7 Size of section headers: 40 (bytes) Number of section headers: 21 Section header string table index: 20
python 及系统版本信息( docker 容器)
root@arm32v7-openjdk:/MyApp/pytest# python -V Python 2.7.13 root@arm32v7-openjdk:/MyApp/pytest# uname -a Linux arm32v7-openjdk 4.9.41-moby #1 SMP Wed Sep 6 00:05:16 UTC 2017 armv7l GNU/Linux
python 代码
import ctypes ll = ctypes.cdll.LoadLibrary """ 1 有试过绝对路径和把这个库文件 copy 到 /usr/local/lib/ 目录下 2 文件肯定存在 3 权限是 777 """ lib = ll("./libencrypt.so")
报错信息
root@arm32v7-openjdk:/MyApp/pytest# python test.py Traceback (most recent call last): File "test.py", line 3, in <module> lib = ll("./libencrypt.so") File "/usr/lib/python2.7/ctypes/__init__.py", line 440, in LoadLibrary return self._dlltype(name) File "/usr/lib/python2.7/ctypes/__init__.py", line 362, in __init__ self._handle = _dlopen(self._name, mode) OSError: ./libencrypt.so: cannot open shared object file: No such file or directory
![]() | 1 checgg OP 顺便一提,用 java 写也是报同样的错 ``` public class test { public static void main(String[] args) { System.out.print("Hello world"); String so = "./libencrypt.so"; System.load(so); } } ``` |
![]() | 2 Xiaobaixiao 2018-05-13 12:24:22 +08:00 把 test.py 移动到 libencrypt.so 所在文件夹,或者添加指定执行该命令的文件夹参数试试(如果有) |
![]() | 3 checgg OP @Xiaobaixiao 是在同目录. |
![]() | 4 virusdefender 2018-05-13 12:53:16 +08:00 strace python test.py 看看系统调用 |
5 wevsty 2018-05-13 13:14:07 +08:00 提示不是很清楚么 cannot open shared object file: No such file or directory 找不到 libencrypt.so 这个文件,检查路径,工作目录,或者干脆写绝对路径上去。 |
6 rookiebulls 2018-05-13 13:40:57 +08:00 via iPhone 路径问题,拿到当前 py 脚本的路径,再 os.path.join 拼一下就可以了 |
![]() | 7 zsj950618 2018-05-13 14:58:35 +08:00 ldd libencrypt.so 看下,也有可能是 ld 路径错了。 |
![]() | 8 izoabr 2018-05-14 08:53:38 +08:00 ctypes.cdll.LoadLibrary 的 path 问题,你试试放到 python 的 lib 目录里去调用 |