如何在 Ubuntu 22.04 上从源代码安装 glibc 2.31

如何在 Ubuntu 22.04 上从源代码安装 glibc 2.31

我正在尝试在 Ubuntu 22.04 LTS 上编译 glibc 2.31。

我关注了这个答案作为模板,这非常有用。

我的问题是,运行 make 时出现未定义的引用:

...

make[2]: Entering directory '/home/user/glibc/glibc-2.31/support'
gcc -Wl,-rpath-link=/home/user/glibc/glibc-2.31-build:/home/user/glibc/glibc-2.31-build/math:/home/user/glibc/glibc-2.31-build/elf:/home/user/glibc/glibc-2.31-build/dlfcn:/home/user/glibc/glibc-2.31-build/nss:/home/user/glibc/glibc-2.31-build/nis:/home/user/glibc/glibc-2.31-build/rt:/home/user/glibc/glibc-2.31-build/resolv:/home/user/glibc/glibc-2.31-build/mathvec:/home/user/glibc/glibc-2.31-build/support:/home/user/glibc/glibc-2.31-build/crypt:/home/user/glibc/glibc-2.31-build/nptl -pie -Wl,-O1 -nostdlib -nostartfiles -o /home/user/glibc/glibc-2.31-build/support/test-container    -Wl,-z,combreloc -Wl,-z,relro -Wl,--hash-style=both /home/user/glibc/glibc-2.31-build/csu/Scrt1.o /home/user/glibc/glibc-2.31-build/csu/crti.o `gcc  --print-file-name=crtbeginS.o` /home/user/glibc/glibc-2.31-build/support/test-container.o /home/user/glibc/glibc-2.31-build/support/libsupport_nonshared.a -Wl,-dynamic-linker=/home/user/glibc/glibc-2.31-install/lib/ld-linux-x86-64.so.2  /home/user/glibc/glibc-2.31-build/libc.so.6 /home/user/glibc/glibc-2.31-build/libc_nonshared.a -Wl,--as-needed /home/user/glibc/glibc-2.31-build/elf/ld.so -Wl,--no-as-needed -lgcc  `gcc  --print-file-name=crtendS.o` /home/user/glibc/glibc-2.31-build/csu/crtn.o
gcc -Wl,-rpath-link=/home/user/glibc/glibc-2.31-build:/home/user/glibc/glibc-2.31-build/math:/home/user/glibc/glibc-2.31-build/elf:/home/user/glibc/glibc-2.31-build/dlfcn:/home/user/glibc/glibc-2.31-build/nss:/home/user/glibc/glibc-2.31-build/nis:/home/user/glibc/glibc-2.31-build/rt:/home/user/glibc/glibc-2.31-build/resolv:/home/user/glibc/glibc-2.31-build/mathvec:/home/user/glibc/glibc-2.31-build/support:/home/user/glibc/glibc-2.31-build/crypt:/home/user/glibc/glibc-2.31-build/nptl -pie -Wl,-O1 -nostdlib -nostartfiles -o /home/user/glibc/glibc-2.31-build/support/shell-container    -Wl,-z,combreloc -Wl,-z,relro -Wl,--hash-style=both /home/user/glibc/glibc-2.31-build/csu/Scrt1.o /home/user/glibc/glibc-2.31-build/csu/crti.o `gcc  --print-file-name=crtbeginS.o` /home/user/glibc/glibc-2.31-build/support/shell-container.o /home/user/glibc/glibc-2.31-build/support/libsupport_nonshared.a  -Wl,-dynamic-linker=/home/user/glibc/glibc-2.31-install/lib/ld-linux-x86-64.so.2  /home/user/glibc/glibc-2.31-build/libc.so.6 /home/user/glibc/glibc-2.31-build/libc_nonshared.a -Wl,--as-needed /home/user/glibc/glibc-2.31-build/elf/ld.so -Wl,--no-as-needed -lgcc  `gcc  --print-file-name=crtendS.o` /home/user/glibc/glibc-2.31-build/csu/crtn.o
gcc -Wl,-rpath-link=/home/user/glibc/glibc-2.31-build:/home/user/glibc/glibc-2.31-build/math:/home/user/glibc/glibc-2.31-build/elf:/home/user/glibc/glibc-2.31-build/dlfcn:/home/user/glibc/glibc-2.31-build/nss:/home/user/glibc/glibc-2.31-build/nis:/home/user/glibc/glibc-2.31-build/rt:/home/user/glibc/glibc-2.31-build/resolv:/home/user/glibc/glibc-2.31-build/mathvec:/home/user/glibc/glibc-2.31-build/support:/home/user/glibc/glibc-2.31-build/crypt:/home/user/glibc/glibc-2.31-build/nptl -pie -Wl,-O1 -nostdlib -nostartfiles -o /home/user/glibc/glibc-2.31-build/support/echo-container    -Wl,-z,combreloc -Wl,-z,relro -Wl,--hash-style=both /home/user/glibc/glibc-2.31-build/csu/Scrt1.o /home/user/glibc/glibc-2.31-build/csu/crti.o `gcc  --print-file-name=crtbeginS.o` /home/user/glibc/glibc-2.31-build/support/echo-container.o /home/user/glibc/glibc-2.31-build/support/libsupport_nonshared.a  -Wl,-dynamic-linker=/home/user/glibc/glibc-2.31-install/lib/ld-linux-x86-64.so.2  /home/user/glibc/glibc-2.31-build/libc.so.6 /home/user/glibc/glibc-2.31-build/libc_nonshared.a -Wl,--as-needed /home/user/glibc/glibc-2.31-build/elf/ld.so -Wl,--no-as-needed -lgcc  `gcc  --print-file-name=crtendS.o` /home/user/glibc/glibc-2.31-build/csu/crtn.o
gcc -Wl,-rpath-link=/home/user/glibc/glibc-2.31-build:/home/user/glibc/glibc-2.31-build/math:/home/user/glibc/glibc-2.31-build/elf:/home/user/glibc/glibc-2.31-build/dlfcn:/home/user/glibc/glibc-2.31-build/nss:/home/user/glibc/glibc-2.31-build/nis:/home/user/glibc/glibc-2.31-build/rt:/home/user/glibc/glibc-2.31-build/resolv:/home/user/glibc/glibc-2.31-build/mathvec:/home/user/glibc/glibc-2.31-build/support:/home/user/glibc/glibc-2.31-build/crypt:/home/user/glibc/glibc-2.31-build/nptl -pie -Wl,-O1 -nostdlib -nostartfiles -o /home/user/glibc/glibc-2.31-build/support/true-container    -Wl,-z,combreloc -Wl,-z,relro -Wl,--hash-style=both /home/user/glibc/glibc-2.31-build/csu/Scrt1.o /home/user/glibc/glibc-2.31-build/csu/crti.o `gcc  --print-file-name=crtbeginS.o` /home/user/glibc/glibc-2.31-build/support/true-container.o /home/user/glibc/glibc-2.31-build/support/libsupport_nonshared.a  -Wl,-dynamic-linker=/home/user/glibc/glibc-2.31-install/lib/ld-linux-x86-64.so.2  /home/user/glibc/glibc-2.31-build/libc.so.6 /home/user/glibc/glibc-2.31-build/libc_nonshared.a -Wl,--as-needed /home/user/glibc/glibc-2.31-build/elf/ld.so -Wl,--no-as-needed -lgcc  `gcc  --print-file-name=crtendS.o` /home/user/glibc/glibc-2.31-build/csu/crtn.o
gcc -Wl,-rpath-link=/home/user/glibc/glibc-2.31-build:/home/user/glibc/glibc-2.31-build/math:/home/user/glibc/glibc-2.31-build/elf:/home/user/glibc/glibc-2.31-build/dlfcn:/home/user/glibc/glibc-2.31-build/nss:/home/user/glibc/glibc-2.31-build/nis:/home/user/glibc/glibc-2.31-build/rt:/home/user/glibc/glibc-2.31-build/resolv:/home/user/glibc/glibc-2.31-build/mathvec:/home/user/glibc/glibc-2.31-build/support:/home/user/glibc/glibc-2.31-build/crypt:/home/user/glibc/glibc-2.31-build/nptl -pie -Wl,-O1 -nostdlib -nostartfiles -o /home/user/glibc/glibc-2.31-build/support/links-dso-program    -Wl,-z,combreloc -Wl,-z,relro -Wl,--hash-style=both /home/user/glibc/glibc-2.31-build/csu/Scrt1.o /home/user/glibc/glibc-2.31-build/csu/crti.o `gcc  --print-file-name=crtbeginS.o` /home/user/glibc/glibc-2.31-build/support/links-dso-program.o -lstdc++ -lgcc -lgcc_s  -Wl,-dynamic-linker=/home/user/glibc/glibc-2.31-install/lib/ld-linux-x86-64.so.2  /home/user/glibc/glibc-2.31-build/libc.so.6 /home/user/glibc/glibc-2.31-build/libc_nonshared.a -Wl,--as-needed /home/user/glibc/glibc-2.31-build/elf/ld.so -Wl,--no-as-needed -lgcc  `gcc  --print-file-name=crtendS.o` /home/user/glibc/glibc-2.31-build/csu/crtn.o
/home/user/binutils/binutils-2.32-install/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/8/libstdc++.so: undefined reference to `fstat64@GLIBC_2.33'
/home/user/binutils/binutils-2.32-install/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/8/libstdc++.so: undefined reference to `pthread_key_create@GLIBC_2.34'
/home/user/binutils/binutils-2.32-install/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/8/libstdc++.so: undefined reference to `pthread_rwlock_unlock@GLIBC_2.34'
/home/user/binutils/binutils-2.32-install/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/8/libstdc++.so: undefined reference to `pthread_detach@GLIBC_2.34'
/home/user/binutils/binutils-2.32-install/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/8/libstdc++.so: undefined reference to `pthread_setspecific@GLIBC_2.34'
/home/user/binutils/binutils-2.32-install/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/libgcc_s.so.1: undefined reference to `_dl_find_object@GLIBC_2.35'
/home/user/binutils/binutils-2.32-install/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/8/libstdc++.so: undefined reference to `__libc_single_threaded@GLIBC_2.32'
/home/user/binutils/binutils-2.32-install/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/8/libstdc++.so: undefined reference to `pthread_join@GLIBC_2.34'
/home/user/binutils/binutils-2.32-install/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/8/libstdc++.so: undefined reference to `pthread_rwlock_wrlock@GLIBC_2.34'
/home/user/binutils/binutils-2.32-install/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/8/libstdc++.so: undefined reference to `pthread_getspecific@GLIBC_2.34'
/home/user/binutils/binutils-2.32-install/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/8/libstdc++.so: undefined reference to `pthread_key_delete@GLIBC_2.34'
/home/user/binutils/binutils-2.32-install/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/8/libstdc++.so: undefined reference to `lstat@GLIBC_2.33'
/home/user/binutils/binutils-2.32-install/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/8/libstdc++.so: undefined reference to `stat@GLIBC_2.33'
/home/user/binutils/binutils-2.32-install/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/8/libstdc++.so: undefined reference to `pthread_once@GLIBC_2.34'
/home/user/binutils/binutils-2.32-install/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/8/libstdc++.so: undefined reference to `pthread_rwlock_rdlock@GLIBC_2.34'
/home/user/binutils/binutils-2.32-install/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/8/libstdc++.so: undefined reference to `pthread_create@GLIBC_2.34'
collect2: error: ld returned 1 exit status
make[2]: *** [../Rules:215: /home/user/glibc/glibc-2.31-build/support/links-dso-program] Error 1
make[2]: Leaving directory '/home/user/glibc/glibc-2.31/support'
make[1]: *** [Makefile:470: support/others] Error 2
make[1]: Leaving directory '/home/user/glibc/glibc-2.31'
make: *** [Makefile:9: all] Error 2

最初,我尝试过:

gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
GNU ld (GNU Binutils for Ubuntu) 2.38

但是,失败之后我尝试(并且以同样的方式失败了):

gcc (Ubuntu 12.3.0-1ubuntu1~22.04) 12.3.0
GNU ld (GNU Binutils for Ubuntu) 2.38

该过程在 glibc 2.31 和 2.32 中失败,但对 glibc 2.35 有效。

最后,我实际阅读了 INSTALL 文档,并且看到:

* GCC 6.2 or newer

     GCC 6.2 or higher is required.  In general it is recommended to use
     the newest version of the compiler that is known to work for
     building the GNU C Library, as newer compilers usually produce
     better code.  As of release time, GCC 9.2.1 is the newest compiler
     verified to work to build the GNU C Library.

     For multi-arch support it is recommended to use a GCC which has
     been built with support for GNU indirect functions.  This ensures
     that correct debugging information is generated for functions
     selected by IFUNC resolvers.  This support can either be enabled by
     configuring GCC with '--enable-gnu-indirect-function', or by
     enabling it by default by setting 'default_gnu_indirect_function'
     variable for a particular architecture in the GCC source file
     'gcc/config.gcc'.

     You can use whatever compiler you like to compile programs that use
     the GNU C Library.

     Check the FAQ for any special compiler issues on particular
     platforms.

* GNU 'binutils' 2.25 or later

     You must use GNU 'binutils' (as and ld) to build the GNU C Library.
     No other assembler or linker has the necessary functionality at the
     moment.  As of release time, GNU 'binutils' 2.32 is the newest
     verified to work to build the GNU C Library.

因此,我根据以下接受答案的出色建议构建了 binutils 2.32这个问题

然后,我将该版本的 binutils 放在 PATH 变量的顶部,得到以下结果:

gcc --version
gcc (Ubuntu 8.4.0-3ubuntu2) 8.4.0

ld --version
GNU ld (GNU Binutils) 2.32

as --version
GNU assembler (GNU Binutils) 2.32

但我仍然遇到相同的未定义引用错误...我迷路了。

任何帮助都将不胜感激。提前致谢。

相关内容