【问题标题】:Relocation R_X86_64_32S against '_Py_NotImplementedStruct' can not be used when making a shared object; recompile with -fPIC制作共享对象时,不能使用针对 '_Py_NotImplementedStruct' 的重定位 R_X86_64_32S;使用 -fPIC 重新编译
【发布时间】:2017-07-23 18:57:19
【问题描述】:

我正在尝试安装dlib Python 库。在某些系统上(macOS,库存 Ubuntu 14.04)pip install dlib 工作正常,但在作为我们 CircleCI 环境一部分的 Ubuntu 14.x 中,它会失败并出现以下错误。

Linking CXX shared library dlib.so
   /usr/bin/ld: /opt/circleci/python/2.7.11/lib/libpython2.7.a(abstract.o): relocation R_X86_64_32S against '_Py_NotImplementedStruct' can not be used when making a shared object; recompile with -fPIC
   error: cmake build failed!

可能出了什么问题?

【问题讨论】:

标签: python dlib


【解决方案1】:

问题是 Python 需要使用 --enable-shared 标志编译,dlib 安装才能成功。虽然在某些情况下系统 Python 是使用此标志构建的(例如在 Ubuntu 上),但我们在 CI 环境中使用的那个是通过 pyenv 安装的,默认情况下没有设置它。

解决方案是重新安装 pyenv 提供的 Python,并设置如下标志:

PYTHON_CONFIGURE_OPTS="--enable-shared" pyenv install --force 2.7.11

为了确保它被使用: machine: python: version: 2.7.11 # Has to match the pyenv-installed version

【讨论】:

    【解决方案2】:

    作为一个仅供参考,我的特殊情况是通过将“/usr/local/lib/libpython2.7.a”重命名为“/usr/local/lib/libpython2.7.a.moved”来解决的。根据 'yum whatprovides /usr/local/lib/libpython2.7.a' 输出,这不是作为通过 yum 安装的任何软件包的一部分安装的。在这种情况下将其移开,解决了我的问题。

    这是我原来的错误信息:

      /usr/bin/ld: /usr/local/lib/libpython2.7.a(abstract.o): relocation R_X86_64_32S against `_Py_NotImplementedStruct' can not be used when making a shared object; recompile with -fPIC
    

    /usr/local/lib/libpython2.7.a:添加符号时出错:值错误 collect2:错误:ld 返回 1 个退出状态

    鉴于我安装的软件包都没有占用 .a 库,因此将其移到一边对我来说是一种选择。

    【讨论】:

      【解决方案3】:

      在亚马逊 docker 容器 amazon-linux-python-3.6 中为 aws lambda python 3.6 构建 matplotlibscikit-image 的依赖项)时遇到了类似的问题。

      简而言之,matplotlib 给出的错误与 OP 对/usr/lib/libpython3.6m.a 的错误相同。原来亚马逊 docker 容器中有两个这样的库:

      find / -name "libpython3.6m.a"
      /usr/lib/libpython3.6m.a
      /usr/lib/python3.6/config-3.6m-x86_64-linux-gnu/libpython3.6m.a
      

      所以我只是将/usr/lib/libpython3.6m.a 重命名为别的东西,这样matplotlib 就不会使用它,并选择了第二个选项:

      enter code heremv /usr/lib/libpython3.6m.a /usr/lib/libpython3.6m.a.moved

      此更改后,scikit-image 已成功使用 pip3 install --no-binary scikit-image scikit-image

      【讨论】:

        猜你喜欢
        • 2016-06-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-05-22
        • 2017-04-10
        • 1970-01-01
        • 2017-07-22
        • 1970-01-01
        相关资源
        最近更新 更多