本文记录了在Ubuntu24.04-x86_64 gcc-13.2.0环境下编译glibc-2.40出现的一系列错误以及解决方法。

问题1

wctomb.c:57:1: error: ‘artificialattribute ignored [-Werror=attributes]
   57 | libc_hidden_def (wctomb)

解决方法

增加CFLAGS参数:../configure CFLAGS="-U_FORTIFY_SOURCE"

相关引用

Build fail on Ubuntu 24.04 (sourceware.org)

问题2

In file included from <command-line>:
./../include/libc-symbols.h:75:3: error: #error "glibc cannot be compiled without optimization"
   75 | # error "glibc cannot be compiled without optimization"
      |   ^~~~~
In file included from <command-line>:
./../include/libc-symbols.h:75:3: error: #error "glibc cannot be compiled without optimization"
   75 | # error "glibc cannot be compiled without optimization"
      |   ^~~~~
In file included from <command-line>:
./../include/libc-symbols.h:75:3: error: #error "glibc cannot be compiled without optimization"
   75 | # error "glibc cannot be compiled without optimization"
      |   ^~~~~
In file included from <command-line>:
./../include/libc-symbols.h:75:3: error: #error "glibc cannot be compiled without optimization"
   75 | # error "glibc cannot be compiled without optimization"
      |   ^~~~~
In file included from <command-line>:
./../include/libc-symbols.h:75:3: error: #error "glibc cannot be compiled without optimization"
   75 | # error "glibc cannot be compiled without optimization"
      |   ^~~~~
In file included from <command-line>:
./../include/libc-symbols.h:75:3: error: #error "glibc cannot be compiled without optimization"
   75 | # error "glibc cannot be compiled without optimization"
      |   ^~~~~
make[2]: *** [../o-iterator.mk:9: /home/blduan/projects/open_source/glibc-2.40/build/stdlib/inlines.os] Error 1
make[2]: *** Waiting for unfinished jobs....
make[2]: *** [../o-iterator.mk:9: /home/blduan/projects/open_source/glibc-2.40/build/stdlib/divrem.os] Error 1
make[2]: *** [../o-iterator.mk:9: /home/blduan/projects/open_source/glibc-2.40/build/stdlib/mul.os] Error 1
make[2]: *** [../o-iterator.mk:9: /home/blduan/projects/open_source/glibc-2.40/build/stdlib/divmod_1.os] Error 1
make[2]: *** [../o-iterator.mk:9: /home/blduan/projects/open_source/glibc-2.40/build/stdlib/mod_1.os] Error 1
make[2]: *** [../o-iterator.mk:9: /home/blduan/projects/open_source/glibc-2.40/build/stdlib/wctomb.os] Error 1
make[2]: Leaving directory '/home/blduan/projects/open_source/glibc-2.40/stdlib'
make[1]: *** [Makefile:484: stdlib/subdir_lib] Error 2
make[1]: Leaving directory '/home/blduan/projects/open_source/glibc-2.40'
make: *** [Makefile:9: all] Error 2

解决方法

../configure CFLAGS="-U_FORTIFY_SOURCE -O2"