无法在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上即可。