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

Posted 悟初境

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 *

以上是关于can not be used when making a shared object; recompile with -fPIC的主要内容,如果未能解决你的问题,请参考以下文章

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

C++链接报错:which may bind externally can not be used when making a shared object; recompile with -fPIC

C++链接报错:which may bind externally can not be used when making a shared object; recompile with -fPIC

eclipse编译动态链接库文件报错 relocation R_X86_64_32 against `.data' can not be used when making a shared o

relocation R_X86_64_32S against `.data‘ can not be used when making a PIE object; recompile with -fP

relocation R_X86_64_32 against `.rodata‘ can not be used when making a shared object; recompile with