奇怪的rpath问题与python3扩展

时间:2017-05-03 17:19:07

标签: python c linux

我正在尝试在Python中创建扩展模块。它是现有C库(.so文件)的包装器,我遇到了rpath问题。

当我这样做时:

rm -rf build
python3 setup.py build_ext --rpath=$ORIGIN
ldd build/lib.linux-x86_64-3.5/mymodule.cpython-35m-x86_64-linux-gnu.so 

我明白了:

linux-vdso.so.1 (0x00007ffc5aab7000)
libmylibrary.so => not found
libpython3.5m.so.1.0 => /lib64/libpython3.5m.so.1.0 (0x00007f38a0a6b000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f38a084d000)
libc.so.6 => /lib64/libc.so.6 (0x00007f38a0487000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007f38a0283000)
libutil.so.1 => /lib64/libutil.so.1 (0x00007f38a007e000)
libm.so.6 => /lib64/libm.so.6 (0x00007f389fd75000)
/lib64/ld-linux-x86-64.so.2 (0x0000560d8fb8f000)

查看如何找不到libmylibrary.so?

但是当我这样做的时候:

rm -rf build
python3 setup.py build_ext
ldd build/lib.linux-x86_64-3.5/mymodule.cpython-35m-x86_64-linux-gnu.so 

我明白了:

linux-vdso.so.1 (0x00007ffc5aab7000)
libpython3.5m.so.1.0 => /lib64/libpython3.5m.so.1.0 (0x00007f38a0a6b000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f38a084d000)
libc.so.6 => /lib64/libc.so.6 (0x00007f38a0487000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007f38a0283000)
libutil.so.1 => /lib64/libutil.so.1 (0x00007f38a007e000)
libm.so.6 => /lib64/libm.so.6 (0x00007f389fd75000)
/lib64/ld-linux-x86-64.so.2 (0x0000560d8fb8f000)

了解libmylibrary.so是如何丢失的?

在Python中,在任何一种情况下,都找不到libmylibrary.so中的1包裹函数

它说:

$ python3
Python 3.5.3 (default, Apr 24 2017, 13:32:13) 
[GCC 6.3.1 20161221 (Red Hat 6.3.1-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import mylibrary
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: /home/me/projectx/venv/lib/python3.5/site-packages/mylibrary.cpython-35m-x86_64-linux-gnu.so: undefined symbol: my_special_function

0 个答案:

没有答案