python - 重定位 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 的错误仍然存在
解决方案
选项1
使用构建/编译 Python--enable-shared
选项 2
错误建议使用-fPIC
所以可以选择
CFLAGS=-fPIC
在 make install 或 [等效构建步骤]
两者都应该工作。
推荐阅读
- javascript - 使用 Node.js axios 时可能出现的网络错误是什么
- c# - 有没有办法使用连接的字符串键访问嵌套字典?
- json - 如何使用 Heroku 日志消耗获取 json 元数据对象
- javascript - React Portals 如何在不同的子树中保存来自提供者的上下文?
- python - 无法弄清楚 pytorch 代码中的就地操作?
- java - Jooq 按已知数量的参数排序
- regex - 获取可能包含多个函数作为参数的函数参数
- r - 如何减少 ggraph 弧图中的节点?
- javascript - 确定是否在组件内提交了表单
- ldap - RADIUS 与 Azure Active Directory 域服务(LDAP 和 NPS)