首页 > 解决方案 > 重定位 R_X86_64_PC32 对符号 `_PyRuntime' 在制作共享对象时不能使用;使用 -fPIC 重新编译

问题描述

在 64 位机器上使用 Python3.7 构建库时出现以下链接错误。

 /usr/bin/ld: /usr/local/lib/libpython3.7m.a(ceval.o): relocation R_X86_64_PC32 against symbol `_PyRuntime' can not be used when making a shared object; recompile with -fPIC
    /usr/bin/ld: final link failed: Bad value
    collect2: error: ld returned 1 exit status

在同一台机器上,如果我安装了一个 miniconda https://docs.conda.io/en/latest/miniconda.html [Py 3.8 for 64bit],则该库在该 conda 环境中安装良好,没有任何错误。

我尝试通过添加来构建 Py3.7

export CFLAGS="$CFLAGS -fPIC"

但是,python3.7 的错误仍然存​​在

标签: pythoncpython-3.xpython-3.7

解决方案


选项1

使用构建/编译 Python--enable-shared

选项 2

错误建议使用-fPIC 所以可以选择

CFLAGS=-fPIC

在 make install 或 [等效构建步骤]

两者都应该工作。


推荐阅读