使用较新版本的 glibc 时出错

Error while using a newer version of glibc

我正在尝试在 linux 服务器上安装 tensorflow,我只是一个没有 root 权限的用户。当我通过跳转服务器 ssh 到它时,我无法传输文件 to/from。系统如下:

Linux THENAME_OF_SURVER 2.6.32-573.18.1.el6.x86_64 #1 SMP Tue Feb 9 22:46:17 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

我通过pip install tensorflow安装了tensorflow,一个tensorflow程序会显示如下:

ImportError: /lib64/libc.so.6: version `GLIBC_2.16' not found

我安装了新版本的 glibc

git clone git://sourceware.org/git/glibc.git cd glibc git checkout --track -b local_glibc-2.16 origin/release/2.16/master mkdir build cd build ../configure --prefix=/home/MYNAME/dependency/glibc-2.16 make -j4 make install

按照网上的说明,我改了环境变量:

export LD_LIBRARY_PATH=/home/MYNAME/dependency/glibc-2.16/lib

但这让我遇到了一个问题:我无法使用任何命令。例如,我调用 ls,它会这样警告我:

ls: error while loading shared libraries: __vdso_time: invalid mode for dlopen(): Invalid argument

然后我按照另一条指令 运行 命令如下:

/home/MYNAME/dependency/glibc-2.16/lib/ld-linux-x86-64.so.2 --library-path /home/MYNAME/dependency/glibc-2.16/lib:$LD_LIBRARY_PATH:/path/to/gcc-5.2.0/lib64:/usr/lib64/:/usr/lib64/ ls (我不知道在哪里可以找到与 gcc-5.2.0 类似的文件夹,我的 which gcc 显示 /usr/local/sbin/gcc,但它 links 到 /usr/local/gcc-5.3.0/bin/gcc,这不有一个 lib64 子文件夹)

但随后出现以下警告:

ls: error while loading shared libraries: ls: cannot open shared object file

我知道我可以通过将变量导出为空来再次使用 ls。但是我还是不能使用新版本的glibc。谁能帮助我如何正确 link 新的 glibc?如有任何建议,我们将不胜感激!

编辑: 所以进度如下:

  1. LD_LIBRARY_PATH=/home/MYNAME/dependency/glibc-2.16/lib python
    会导致 python: error while loading shared libraries: __vdso_time: invalid mode for dlopen(): Invalid argument

  2. /home/MYNAME/dependency/glibc-2.16/lib/ld-2.16.so python
    会导致 python: error while loading shared libraries: __vdso_time: invalid mode for dlopen(): Invalid argument

编辑 2 和摘要:

为了使 Employed Russian 的回答更加详细,我将在此处粘贴我的最终解决方案。

我的目标是在我没有root权限的服务器上Python使用tensorflow。我在导入 tensorflow 时被警告 ImportError: /lib64/libc.so.6: version 'GLIBC_2.16' not found

根据 Employed Russian 的回答,我使用以下命令 运行 我的命令:

LD_LIBRARY_PATH=/home/USERNAME/dependency/glibc-2.17/lib/:/lib64/:/usr/local/gcc-5.3.0/lib64/ /home/USERNAME/dependency/glibc-2.17/lib/ld-2.17.so /home/USERNAME/anaconda2/bin/python

将命令拆分为以下部分(我会使用 ??? 来表示不同人的不同路径。):

  1. LD_LIBRARY_PATH=
    • 这部分处理依赖关系
    • :表示拆分
    • ???/glibc-2.17/lib/
    • /lib64//usr/local/gcc-5.3.0/lib64/:我通过 find / -name 'libgcc_s.so.1' 找到了这些文件夹,因为我是
  2. /???/glibc-2.17/lib/ld-2.17.so
  3. /???/python 可执行文件的路径。对于 Python、import sys; print(sys.executable) 查看您的 Python 路径。

其他:

  1. glibc-2.17 从 gnu 下载。我选择了 2.17,因为 tensorflow 需要 2.17,而 2.17 可以正常工作。
  2. 这个解决方案还有一个问题。我有时需要在 Python 中调用 shell 命令,例如 os.system('ls')os.system('python xxx.py')。但如果我以正常方式使用它,它会警告我如下:sh: error while loading shared libraries: __vdso_time: invalid mode for dlopen(): Invalid argument 并且我还没有找到足够好的解决方案。

export LD_LIBRARY_PATH=/home/MYNAME/dependency/glibc-2.16/lib

This answer 解释了为什么 LD_LIBRARY_PATH 不起作用,以及您应该怎么做。

I read your post and tried ...
python: error while loading shared libraries: __vdso_time: invalid mode for dlopen(): Invalid argument

该错误通常表示您在 ld-linuxlibc.so.6 之间存在 不匹配 。他们必须匹配。

如果您通过 /home/MYNAME/.../ld-2.16.so 使用直接加载程序调用,您 还必须 安排 /home/MYNAME/.../libc.so.6 加载。

您可以将 --library-path ... 传递给 ld-2.16.so,或者适当地设置 LD_LIBRARY_PATH

您使用 ld-2.16 --library-path ... ls 的命令 几乎 正确。您缺少的是 ld-2.16 不会 搜索您的 PATH。你需要给它 full 路径名:ld-2.16 --library-path ... /bin/ls.

在我的例子中是 centos 6 和 python for pytorch.

我遇到了诸如此类的错误:

libraries: __vdso_time: invalid mode for dlopen(): Invalid argument

ImportError: /lib64/libc.so.6: version `GLIBC_2.14' not found (required by /home/evaldsu/.conda/envs/conda_env/lib/python3.6/site-

我在本地目录中安装了 glibc-2.17 /opt/exp_soft/tools

然后我安装了conda env补丁工具(也可以使用其他工具安装):

conda install -c conda-forge patchelf

然后我修补了 python 的二进制文件以使用不同的 glibc 路径(您可以对任何二进制文件执行此操作)。请注意,它会改变你 python 二进制文件。

patchelf --set-rpath /opt/exp_soft/tools/glibc-2.17/lib:$HOME/.conda/envs/conda_inf/lib:/usr/lib64:/lib64:/lib --set-interpreter /opt/exp_soft/tools/glibc-2.17/lib/ld-linux-x86-64.so.2 /home/evaldsu/.conda/envs/conda_inf/bin/python3.6

如果您拥有完全管理员权限,另一个选项是只安装此脚本:

https://gist.github.com/harv/f86690fcad94f655906ee9e37c85b174

我发现上述 Employed Russian 提供的信息很有用,但他写的内容并没有真正解决我的问题。那是因为我使用的二进制文件是静态的。正是这个二进制文件调用的 CLI 工具提出了我真正的问题。就像其他人所说的那样,使用环境变量只会让问题变得更糟,因为它只会让我无法使用 shell.

就我而言,我想在 CentOS 6.10 服务器上获得最新的 Vag运行t 版本 (2.2.19) 运行。我希望它能让我 运行 偶尔遇到的问题消失。但是 Vag运行t 的 RPM 并没有安装一个二进制文件。相反,它设置了一个嵌入式目录,其中包含所有 CLI 工具,以及这些 CLI 工具使用的库。当然,他们都需要比我安装的更新的各种版本的 GNU libc。

对我来说,修复至少意味着编译,然后将所需的 GNU libc 版本安装到它自己的路径中。然后修补所有由 Vag运行t 安装的动态链接 binaries/libraries 以使用更新的 GNU libc。最重要的是,我还必须确保 embedded 目录中指向库的各种链接都得到保留(有关更多信息,请参见下文)。这是我为解决问题而编写的脚本(至少,希望,暂时):

#!/bin/bash

cd $HOME/
GLIBC_VERSION="2.17"
GLIBC_PREFIX="/usr/glibc/"
VAGRANT_VERSION="2.2.19"

# Install the basic build system utilities.
yum groupinstall -y "Development tools"
yum install -y curl patchelf

# Grab the tarball with the GNU libc source code.
curl -Lfo glibc-${GLIBC_VERSION}.tar.gz "https://ftp.gnu.org/gnu/glibc/glibc-${GLIBC_VERSION}.tar.gz"
echo "a3b2086d5414e602b4b3d5a8792213feb3be664ffc1efe783a829818d3fca37a  glibc-${GLIBC_VERSION}.tar.gz" | sha256sum -c || exit 1

# Extract the secrets and get ready to rumble.
tar xzvf glibc-${GLIBC_VERSION}.tar.gz

# The configure script requrires an independent build directory.
mkdir -p glibc-build && cd glibc-build

# Configure glibc with a GLIBC_PREFIX so it doesn't conflict with distro libc files..
../glibc-${GLIBC_VERSION}/configure --prefix="${GLIBC_PREFIX}" --libdir="${GLIBC_PREFIX}/lib" \
--libexecdir="${GLIBC_PREFIX}/lib" --enable-multi-arch

# Compile and then install GNU libc.
make -j8 && make install

# Download and install Vagrant.
curl -Lfo vagrant_${VAGRANT_VERSION}_x86_64.rpm "https://releases.hashicorp.com/vagrant/${VAGRANT_VERSION}/vagrant_${VAGRANT_VERSION}_x86_64.rpm"
echo "990e8d2159032915f21c0f1ccdcbca1a394f7937e06e43dc1dabe605d208dc20  vagrant_${VAGRANT_VERSION}_x86_64.rpm" | sha256sum -c || exit 1
yum install -y vagrant_${VAGRANT_VERSION}_x86_64.rpm

# Patch the binaries and shared libraries inside the Vagrant directory, so they use the new version of GNU libc.
(find /opt/vagrant/ -type f -exec file {} \; )| grep "dynamically linked" | awk -F':' '{print }' | while read FILE ; do
  patchelf --set-rpath /opt/vagrant/embedded/lib:/opt/vagrant/embedded/lib64:/usr/glibc/lib:/usr/lib64:/lib64:/lib --set-interpreter /usr/glibc/lib/ld-linux-x86-64.so.2 "${FILE}"
done

该脚本应该非常容易理解,并适应您想要制作的任何 MacGuffin。唯一棘手的部分是我传递给 patchelfrpath。我必须确保它还包含 embedded 下面的库路径,否则 Vag运行 内部的依赖引用会被破坏。

P.S。不要忘记更新您下载的任何文件的哈希值。特别是,您需要 compile/install 不同版本的 GNU libc,您需要更新该散列以匹配您要使用的版本。