Linux编译不同版本glibc(转载)

转载自:https://blog.csdn.net/qq_40827990/article/details/89295472

方法步骤

  1. 在http://ftp.gnu.org/gnu/glibc/网站下载你需要的glibc版本
  2. 解压下载的文件,同时在本目录下创建一个bulid文件夹,在其他目录下建立一个glibc-x.xx目录:
    1 tar -zxvf glibc-2.23.tar.gz
    2 cd glibc-2.23
    3 mkdir build
  3. 进入build目录,然后输入下面的命令,文件的路径自己确定:  
    
    
    1 cd build
    2 CFLAGS="-g -g3 -ggdb -gdwarf-4 -Og -Wno-error=maybe-uninitialized" 
    3 CXXFLAGS="-g -g3 -ggdb -gdwarf-4 -Og -Wno-error=maybe-uninitialized" 
    4 ../configure --prefix=/home/sir/cc-sir/glibc/glibc-2.23/   
    5 $CONFIGURE_FLAGS   //注意,这段代码如果要编译x86环境的libc库,不需要执行。编译ARM64环境的需要先source环境变量,然后执行该句,            
    6 make
    7 make install
  4. 最后进行软链接就可以:
    1 sudo ln -s /home/sir/cc-sir/glibc-2.23/lib/ld-2.23.so 23-linux-x86-64.so.2

    然后检查/lib64目录可以看到新增加的libc:

    1 sir@sir-PC:~/desktop$ ls -l /lib64
    2 总用量 0
    3 lrwxrwxrwx 1 root root 42 4月  14 12:54 23-linux-x86-64.so.2 -> /home/sir/cc-sir/glibc-2.23/lib/ld-2.23.so
    4 lrwxrwxrwx 1 root root 42 4月  14 10:12 26-linux-x86-64.so.2 -> /home/sir/cc-sir/glibc-2.26/lib/ld-2.26.so
    5 lrwxrwxrwx 1 root root 32 11月  3 19:49 ld-linux-x86-64.so.2 -> /lib/x86_64-linux-gnu/ld-2.27.so

    如果编译的glibc版本太低,在make的时候可能会出现一些问题,可能需要自己根据报错的信息,修改源代码;

    报错例子

     1 nis_call.c: In function ‘nis_server_cache_add’:
     2 nis_call.c:682:6: error: suggest explicit braces to avoid ambiguous ‘else’ [-Werror=dangling-else]
     3    if (*loc != NULL)
     4       ^
     5 cc1: all warnings being treated as errors
     6 make[2]: *** [../o-iterator.mk:9:/home/sir/cc-sir/glibc-2.23/nis/nis_call.o] 错误 1
     7 make[2]: 离开目录“/home/sir/tools/glibc-2.23/nis”
     8 make[1]: *** [Makefile:214:nis/others] 错误 2
     9 make[1]: 离开目录“/home/sir/tools/glibc-2.2310 make: *** [Makefile:9:all] 错误 2

    nis_call.cer文件中第682行的if语句没有加‘{ }’,导致语义不明报错,自行补上{ }就可以;

     1 -o /home/sir/cc-sir/glibc-2.23/misc/regexp.os -MD -MP -MF /home/sir/cc-sir/glibc-2.23/misc/regexp.os.dt -MT /home/sir/cc-sir/glibc-2.23/misc/regexp.os
     2 /tmp/cc2dus00.s: Assembler messages:
     3 /tmp/cc2dus00.s: 错误:`loc1@GLIBC_2.2.5' can't be versioned to common symbol 'loc1'
     4 /tmp/cc2dus00.s: 错误:`loc2@GLIBC_2.2.5' can't be versioned to common symbol 'loc2'
     5 /tmp/cc2dus00.s: 错误:`locs@GLIBC_2.2.5' can't be versioned to common symbol 'locs'
     6 make[2]: *** [../o-iterator.mk:9:/home/sir/cc-sir/glibc-2.23/misc/regexp.os] 错误 1
     7 make[2]: 离开目录“/home/sir/tools/glibc-2.23/misc”
     8 make[1]: *** [Makefile:214:misc/subdir_lib] 错误 2
     9 make[1]: 离开目录“/home/sir/tools/glibc-2.2310 make: *** [Makefile:9:all] 错误 2

    将regexp.c源文件中的:

    1 char *loc1
    2 char *loc2
    3 char *locs

    修改为:

    char *loc1 __attribute__ ((nocommon));
    char *loc2 __attribute__ ((nocommon));
    char *locs __attribute__ ((nocommon));

    还有其他的报错都大同小异,修改一下源代码基本都可以解决…

原文地址:https://www.cnblogs.com/zongfanstudy/p/13993674.html