链接器找不到标准 c 库

Linker cannot find standard c library

我对 CentOS 上的库有一些问题。我不确定出了什么问题。当我尝试制作项目时,出现此错误:

gcc -Wall -Winline -O2 -fPIC -g -D_FILE_OFFSET_BITS=64  -o bzip2 bzip2.o -L. -lbz2
/usr/bin/ld: cannot find -lc
collect2: error: ld returned 1 exit status

我可以 - 并且确实 - 创建了一个符号链接,将 /usr/lib64/libc.so 链接到存在的 /usr/lib64/libc-2.17.so,但这只会产生另一个错误:

gcc -Wall -Winline -O2 -fPIC -g -D_FILE_OFFSET_BITS=64  -o bzip2 bzip2.o -L. -lbz2
/usr/lib/gcc/x86_64-redhat-linux/4.8.5/crt1.o: In function `_start':
(.text+0x12): undefined reference to `__libc_csu_fini'
/usr/lib/gcc/x86_64-redhat-linux/4.8.5/crt1.o: In function `_start':
(.text+0x19): undefined reference to `__libc_csu_init'
collect2: error: ld returned 1 exit status

显然工具链坏了。我怎样才能正确修复它?制作符号链接显然不能解决任何问题...

我还尝试使用 yum group remove "Development Tools" 然后 yum group install "Development Tools"

重新安装整个开发工具链

/usr/lib64/libc.so 不是符号 link,它是 linker 脚本。

在 Fedora 上它包含:

/* GNU ld script
   Use the shared library, but some functions are only in
   the static library, so try that secondarily.  */
OUTPUT_FORMAT(elf64-x86-64)
GROUP ( /lib64/libc.so.6 /usr/lib64/libc_nonshared.a  AS_NEEDED ( /lib64/ld-linux-x86-64.so.2 ) )

而且,果然:

$ nm -C --defined-only /usr/lib64/libc_nonshared.a

elf-init.oS:
0000000000000070 T __libc_csu_fini
0000000000000000 T __libc_csu_init
...

/usr/lib64/libc.so 属于 glibc rpm。我建议重新安装它。