python lib error

无法在so中使用libpython.2.7.a

build error msg:

/usr/bin/ld: /usr/local/lib/libpython2.7.a(abstract.o): relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/libpython2.7.a: could not read symbols: Bad value

fix
re-install python

./configure --prefix=/usr/local/  --enable-shared CFLAGS=-fPIC  
make  
make install

未定义符号

  • build error msg
[wei.xiew@xen-a0f1418-102-b unittest]$ scons -U . -j 8
Traceback (most recent call last):
  File "/usr/bin/scons", line 175, in <module>
    import SCons.Script
  File "/usr/lib/scons/SCons/__init__.py", line 43, in <module>
    import SCons.compat
  File "/usr/lib/scons/SCons/compat/__init__.py", line 243, in <module>
    import_as('_scons_subprocess', 'subprocess')
  File "/usr/lib/scons/SCons/compat/__init__.py", line 74, in import_as
    imp.load_module(name, file, filename, suffix_mode_type)
  File "/usr/lib/scons/SCons/compat/_scons_subprocess.py", line 411, in <module>
    import select
ImportError: /usr/local/lib/python2.7/lib-dynload/select.so: undefined symbol: _PyInt_AsInt
  • Trace :
    找到select.so , ldd找到链接的python.so
[wei.xiew@xen-a0f1418-102-b unittest]$ ldd /usr/local/lib/python2.7/lib-dynload/select.so
        linux-vdso.so.1 =>  (0x00007fff58adf000)
        /opt/alisentry/$LIB/alisentry_connect.so => /opt/alisentry/lib64/alisentry_connect.so (0x00007ff32979f000)
        /opt/alisentry/$LIB/alisentry_exec.so => /opt/alisentry/lib64/alisentry_exec.so (0x00007ff32959b000)
        /opt/alisentry/$LIB/alisentry_kill.so => /opt/alisentry/lib64/alisentry_kill.so (0x00007ff329399000)
        libpython2.7.so.1.0 => /usr/lib/libpython2.7.so.1.0 (0x00007ff328fb9000)
        libpthread.so.0 => /lib64/libpthread.so.0 (0x00007ff328d9e000)
        libc.so.6 => /lib64/libc.so.6 (0x00007ff328a46000)
        libdl.so.2 => /lib64/libdl.so.2 (0x00007ff328842000)
        libutil.so.1 => /lib64/libutil.so.1 (0x00007ff32863e000)
        libm.so.6 => /lib64/libm.so.6 (0x00007ff3283bb000)
        /lib64/ld-linux-x86-64.so.2 (0x0000003d46400000)

从链接 的这个libpython2.7.so.1.0的位置来看,就不像是新装的,多半有问题

再readelf -a 查该so是否有对应的符号

readelf -a /usr/lib/libpython2.7.so.1.0 | grep _PyInt_AsInt

果然没有
同样再查新装的libpython2.7.so.1.0,

$ readelf -a /usr/local/lib/libpython2.7.so.1.0 | grep _PyInt_AsInt
0000003849b8  029300000007 R_X86_64_JUMP_SLO 0000000000076350 _PyInt_AsInt + 0
   659: 0000000000076350    84 FUNC    GLOBAL DEFAULT   10 _PyInt_AsInt
  5280: 0000000000076350    84 FUNC    GLOBAL DEFAULT   10 _PyInt_AsInt

符号是存在的, 所以只需要删除老的so, 让select.so链接到新的python so上即可。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值