Linux编译不同版本glibc

方法步骤

  1. 在http://ftp.gnu.org/gnu/glibc/网站下载你需要的glibc版本
  2. 解压下载的文件,同时在本目录下创建一个bulid文件夹,在其他目录下建立一个glibc-x.xx目录:
tar -zxvf glibc-2.23.tar.gz
cd glibc-2.23
mkdir build
  1. 进入build目录,然后输入下面的命令,文件的路径自己确定:
cd build
CFLAGS="-g -g3 -ggdb -gdwarf-4 -Og -Wno-error=maybe-uninitialized" \
CXXFLAGS="-g -g3 -ggdb -gdwarf-4 -Og -Wno-error=maybe-uninitialized" \
../configure --prefix=/home/sir/cc-sir/glibc/glibc-2.23/
make
make install
  1. 最后进行软链接就可以:
sudo ln -s /home/sir/cc-sir/glibc-2.23/lib/ld-2.23.so 23-linux-x86-64.so.2

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

sir@sir-PC:~/desktop$ ls -l /lib64
总用量 0
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
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
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的时候可能会出现一些问题,可能需要自己根据报错的信息,修改源代码;

报错例子

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

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

 -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
/tmp/cc2dus00.s: Assembler messages:
/tmp/cc2dus00.s: 错误:`loc1@GLIBC_2.2.5' can't be versioned to common symbol 'loc1'
/tmp/cc2dus00.s: 错误:`loc2@GLIBC_2.2.5' can't be versioned to common symbol 'loc2'
/tmp/cc2dus00.s: 错误:`locs@GLIBC_2.2.5' can't be versioned to common symbol 'locs'
make[2]: *** [../o-iterator.mk:9:/home/sir/cc-sir/glibc-2.23/misc/regexp.os] 错误 1
make[2]: 离开目录“/home/sir/tools/glibc-2.23/misc”
make[1]: *** [Makefile:214:misc/subdir_lib] 错误 2
make[1]: 离开目录“/home/sir/tools/glibc-2.23”
make: *** [Makefile:9:all] 错误 2

将regexp.c源文件中的:

char *loc1
char *loc2
char *locs

修改为:

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

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

发布了58 篇原创文章 · 获赞 19 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/qq_40827990/article/details/89295472
今日推荐