单个主机上有多个glibc库 [英] Multiple glibc libraries on a single host

查看:197
本文介绍了单个主机上有多个glibc库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

单个主机上有多个glibc库

我的linux(SLES-8)服务器目前有glibc-2.2.5-235,但我有一个程序赢得了在这个版本上工作并且需要glibc-2.3.3。

是否可以在同一个主机上安装多个glibcs​​?



这是我在旧glibc上运行程序时得到的错误:

  ./ myapp :/lib/i686/libc.so.6:未找到'GLIBC_2.3'版本(必需的./myapp)
./myapp:/lib/i686/libpthread.so.0:version'GLIBC_2。 3.2'找不到(需要./myapp)
./myapp:/lib/i686/libc.so.6:未找到'GLIBC_2.3'版本(需要./libxerces-c.so.27 )
./myapp:/lib/ld-linux.so.2:未找到'GLIBC_2.3'版本(需要./libstdc++.so.6)
./myapp:/ lib / i686 / libc.so.6:未找到'GLIBC_2.3'版本(需要使用./libstdc++.so.6)

因此,我创建了一个名为newglibc的新目录,并复制了以下文件:

  libpthread.so.0 
libm.so.6
libc.so.6
ld-2.3.3.so
ld-linux.so.2 - > ld-2.3.3.so

  export LD_LIBRARY_PATH = newglibc:$ LD_LIBRARY_PATH 

但是我得到错误:

  ./ myapp:/lib/ld-linux.so.2:未找到版本'GLIBC_PRIVATE'(必需的通过./newglibc/libpthread.so.0)
./myapp:/lib/ld-linux.so.2:找不到版本'GLIBC_2.3'(libstdc ++。so.6要求)
./myapp:/lib/ld-linux.so.2:未找到'GLIBC_PRIVATE'版本(需要使用./newglibc/libm.so.6)
./myapp:/ lib / ld-linux。 so.2:找不到版本'GLIBC_2.3'(需要使用./newglibc/libc.so.6)
./myapp:/lib/ld-linux.so.2:未找到版本'GLIBC_PRIVATE' (需要./newglibc/libc.so.6)

所以看起来他们仍然在链接到/ lib,而不是从我把它们放在哪里?

谢谢

解决方案

很可能在同一个系统上有多个版本的glibc(我们不过,你需要知道glibc包含许多必须匹配的部分(200多个共享库)。其中一个是ld-linux.so.2,它必须与libc.so.6匹配,否则您会看到您看到的错误。



ld-linux.so.2的绝对路径在链接时硬编码到可执行文件中,链接完成后不能轻易更改。



要构建一个可以与新glibc一起工作的可执行文件,请执行以下操作:

  g ++ main.o -o myapp ... \ 
-Wl, - rpath = / path / to / newglibc \
-Wl, - dynamic-linker = / path / to / newglibc / ld-linux.so .2

-rpath 链接器选项将使运行时加载程序在 / path / to / newglibc 中搜索库(这样您就不必设置 LD_LIBRARY_PATH 在运行它之前),并且 -dynamic-linker 选项将烘焙路径更正为 ld-linux.so.2 myapp 应用程序(例如,因为它是第三个应用程序)。 - 方二进制),不一切都失败了,但它变得更加棘手。一种解决方案是为它设置合适的 chroot 环境。另一种可能是使用 rtldi 二进制编辑器


Multiple glibc libraries on a single host

My linux (SLES-8) server currently has glibc-2.2.5-235, but I have a program which won't work on this version and requires glibc-2.3.3.

Is it possible to have multiple glibcs installed on the same host?

This is the error I get when I run my program on the old glibc:

./myapp: /lib/i686/libc.so.6: version `GLIBC_2.3' not found (required by ./myapp)
./myapp: /lib/i686/libpthread.so.0: version `GLIBC_2.3.2' not found (required by ./myapp)
./myapp: /lib/i686/libc.so.6: version `GLIBC_2.3' not found (required by ./libxerces-c.so.27)
./myapp: /lib/ld-linux.so.2: version `GLIBC_2.3' not found (required by ./libstdc++.so.6)
./myapp: /lib/i686/libc.so.6: version `GLIBC_2.3' not found (required by ./libstdc++.so.6)

So I created a new directory called newglibc and copied the following files in:

libpthread.so.0
libm.so.6
libc.so.6
ld-2.3.3.so
ld-linux.so.2 -> ld-2.3.3.so

and

export LD_LIBRARY_PATH=newglibc:$LD_LIBRARY_PATH

But I get an error:

./myapp: /lib/ld-linux.so.2: version `GLIBC_PRIVATE' not found (required by ./newglibc/libpthread.so.0)
./myapp: /lib/ld-linux.so.2: version `GLIBC_2.3' not found (required by libstdc++.so.6)
./myapp: /lib/ld-linux.so.2: version `GLIBC_PRIVATE' not found (required by ./newglibc/libm.so.6)
./myapp: /lib/ld-linux.so.2: version `GLIBC_2.3' not found (required by ./newglibc/libc.so.6)
./myapp: /lib/ld-linux.so.2: version `GLIBC_PRIVATE' not found (required by ./newglibc/libc.so.6)

So it appears that they are still linking to /lib and not picking up from where I put them?

Thanks

解决方案

It is very possible to have multiple versions of glibc on the same system (we do that every day).

However, you need to know that glibc consists of many pieces (200+ shared libraries) which all must match. One of the pieces is ld-linux.so.2, and it must match libc.so.6, or you'll see the errors you are seeing.

The absolute path to ld-linux.so.2 is hard-coded into the executable at link time, and can not be easily changed after the link is done.

To build an executable that will work with the new glibc, do this:

g++ main.o -o myapp ... \
   -Wl,--rpath=/path/to/newglibc \
   -Wl,--dynamic-linker=/path/to/newglibc/ld-linux.so.2

The -rpath linker option will make the runtime loader search for libraries in /path/to/newglibc (so you wouldn't have to set LD_LIBRARY_PATH before running it), and the -dynamic-linker option will "bake" path to correct ld-linux.so.2 into the application.

If you can't relink the myapp application (e.g. because it is a third-party binary), not all is lost, but it gets trickier. One solution is to set a proper chroot environment for it. Another possibility is to use rtldi and a binary editor.

这篇关于单个主机上有多个glibc库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆