can not be used when making a shared object; recompile with -fPIC

报错信息如下:

      /usr/bin/ld: /usr/local/lib/python3.8/config-3.8-x86_64-linux-gnu/libpython3.8.a(abstract.o): relocation R_X86_64_32S against symbol `_Py_NotImplementedStruct' can not be used when making a shared object; recompile with -fPIC
      /usr/bin/ld: /usr/local/lib/python3.8/config-3.8-x86_64-linux-gnu/libpython3.8.a(boolobject.o): relocation R_X86_64_32S against symbol `_Py_FalseStruct' can not be used when making a shared object; recompile with -fPIC
      /usr/bin/ld: /usr/local/lib/python3.8/config-3.8-x86_64-linux-gnu/libpython3.8.a(bytearrayobject.o): relocation R_X86_64_32 against symbol `_PyByteArray_empty_string' can not be used when making a shared object; recompile with -fPIC
      /usr/bin/ld: /usr/local/lib/python3.8/config-3.8-x86_64-linux-gnu/libpython3.8.a(bytesobject.o): relocation R_X86_64_32 against symbol `_Py_NoneStruct' can not be used when making a shared object; recompile with -fPIC
      /usr/bin/ld: /usr/local/lib/python3.8/config-3.8-x86_64-linux-gnu/libpython3.8.a(call.o): relocation R_X86_64_32 against `.rodata.str1.8' can not be used when making a shared object; recompile with -fPIC
      /usr/bin/ld: /usr/local/lib/python3.8/config-3.8-x86_64-linux-gnu/libpython3.8.a(exceptions.o): relocation R_X86_64_32S against symbol `_Py_NoneStruct' can not be used when making a shared object; recompile with -fPIC
      /usr/bin/ld: /usr/local/lib/python3.8/config-3.8-x86_64-linux-gnu/libpython3.8.a(fileobject.o): relocation R_X86_64_32 against symbol `_Py_NoneStruct' can not be used when making a shared object; recompile with -fPIC
      /usr/bin/ld: /usr/local/lib/python3.8/config-3.8-x86_64-linux-gnu/libpython3.8.a(floatobject.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
      /usr/bin/ld: /usr/local/lib/python3.8/config-3.8-x86_64-linux-gnu/libpython3.8.a(frameobject.o): relocation R_X86_64_32 against symbol `_Py_NoneStruct' can not be used when making a shared object; recompile with -fPIC
      /usr/bin/ld: /usr/local/lib/python3.8/config-3.8-x86_64-linux-gnu/libpython3.8.a(funcobject.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
      /usr/bin/ld: /usr/local/lib/python3.8/config-3.8-x86_64-linux-gnu/libpython3.8.a(iterobject.o): relocation R_X86_64_32 against symbol `_Py_NoneStruct' can not be used when making a shared object; recompile with -fPIC
      /usr/bin/ld: /usr/local/lib/python3.8/config-3.8-x86_64-linux-gnu/libpython3.8.a(listobject.o): relocation R_X86_64_32 against symbol `_Py_NoneStruct' can not be used when making a shared object; recompile with -fPIC

根据错误提示:recompile with -fPIC可以知道是在编译时的问题,所以查看python源码的 configure文件,发现里面有参数:

  --enable-shared         disable/enable building shared python library

所以重新编译python:./configure --enable-optimizations --enable-shared

完整命令如下:

# 安装python3.8
RUN yum install -y openssl-devel zlib-devel libffi-devel xz-devel xmlsec1-devel libtool-ltdl-devel && \
    tar xvf Python-3.8.13.tar.xz && cd Python-3.8*/ && ./configure --enable-optimizations --enable-shared && make altinstall && \
    ln -s /usr/local/bin/python3.8 /usr/local/bin/python3 && echo "alias python='/usr/local/bin/python3.8'" >> /etc/profile  \
    && echo "/usr/local/lib/" >> /etc/ld.so.conf \
    && ldconfig && yum clean all && rm -rf *
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值