Multiple glibc libraries on a single host

后端 未结 11 1564
轮回少年
轮回少年 2020-11-21 05:13

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

11条回答
  •  眼角桃花
    2020-11-21 06:06

    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.

提交回复
热议问题