Linux編譯不同版本glibc(轉載)
阿新 • • 發佈:2020-11-17
轉載自:https://blog.csdn.net/qq_40827990/article/details/89295472
方法步驟
- 在http://ftp.gnu.org/gnu/glibc/網站下載你需要的glibc版本
- 解壓下載的檔案,同時在本目錄下建立一個bulid資料夾,在其他目錄下建立一個glibc-x.xx目錄:
1 tar -zxvf glibc-2.23.tar.gz 2 cd glibc-2.23 3 mkdir build
- 進入build目錄,然後輸入下面的命令,檔案的路徑自己確定:
1 cd build 2 CFLAGS="-g -g3 -ggdb -gdwarf-4 -Og -Wno-error=maybe-uninitialized
- 最後進行軟連結就可以:
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
如果編譯的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.23” 10 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.23” 10 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));
還有其他的報錯都大同小異,修改一下原始碼基本都可以解決…