helloworld.c无法编译100多个错误

Fra*_*ris 4 c configuration ubuntu-11.10

我相信我正在处理某种被破坏的库.我写了以下代码:

//helloworld.c                                                                  

#include <stdio.h>

int main()
{
  printf("Hello, world!\n");

  return 0;
}
Run Code Online (Sandbox Code Playgroud)

并使用以下命令编译它:

gcc helloworld.c
Run Code Online (Sandbox Code Playgroud)

我得到的错误很多.这是一个示例:

/usr/include/stdio.h:510: error: expected ‘)’ before ‘*’ token
/usr/include/stdio.h:514: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__wur’
/usr/include/stdio.h:517: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__THROW’
/usr/include/stdio.h:524: error: expected declaration specifiers before ‘__END_NAMESPACE_C99’
/usr/include/stdio.h:534: error: expected ‘)’ before ‘*’ token
/usr/include/stdio.h:540: error: storage class specified for parameter ‘getchar’
/usr/include/stdio.h:541: error: expected declaration specifiers before ‘__END_NAMESPACE_STD’
/usr/include/stdio.h:553: error: storage class specified for parameter ‘getchar_unlocked’
/usr/include/stdio.h:563: error: expected ‘)’ before ‘*’ token
/usr/include/stdio.h:567: error: expected declaration specifiers before ‘__BEGIN_NAMESPACE_STD’
/usr/include/stdio.h:576: error: expected declaration specifiers or ‘...’ before ‘FILE’
/usr/include/stdio.h:576: error: storage class specified for parameter ‘putc’
/usr/include/stdio.h:582: error: storage class specified for parameter ‘putchar’
/usr/include/stdio.h:583: error: expected declaration specifiers before ‘__END_NAMESPACE_STD’
/usr/include/stdio.h:604: error: expected declaration specifiers or ‘...’ before ‘FILE’
/usr/include/stdio.h:604: error: storage class specified for parameter ‘putc_unlocked’
/usr/include/stdio.h:605: error: storage class specified for parameter ‘putchar_unlocked’
/usr/include/stdio.h:612: error: expected ‘)’ before ‘*’ token
/usr/include/stdio.h:615: error: expected declaration specifiers or ‘...’ before ‘FILE’
/usr/include/stdio.h:615: error: storage class specified for parameter ‘putw’
/usr/include/stdio.h:619: error: expected declaration specifiers before ‘__BEGIN_NAMESPACE_STD’
/usr/include/stdio.h:632: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__wur’
/usr/include/stdio.h:633: error: expected declaration specifiers before ‘__END_NAMESPACE_STD’
/usr/include/stdio.h:661: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘getdelim’
/usr/include/stdio.h:671: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘getline’
/usr/include/stdio.h:677: error: expected declaration specifiers before ‘__BEGIN_NAMESPACE_STD’
/usr/include/stdio.h:688: error: storage class specified for parameter ‘puts’
/usr/include/stdio.h:695: error: expected declaration specifiers or ‘...’ before ‘FILE’
/usr/include/stdio.h:695: error: storage class specified for parameter ‘ungetc’
/usr/include/stdio.h:702: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘fread’
/usr/include/stdio.h:708: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘fwrite’
/usr/include/stdio.h:710: error: expected declaration specifiers before ‘__END_NAMESPACE_STD’
/usr/include/stdio.h:732: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘fwrite_unlocked’
/usr/include/stdio.h:737: error: expected declaration specifiers before ‘__BEGIN_NAMESPACE_STD’
/usr/include/stdio.h:747: error: expected ‘)’ before ‘*’ token
/usr/include/stdio.h:752: error: expected ‘)’ before ‘*’ token
/usr/include/stdio.h:753: error: expected declaration specifiers before ‘__END_NAMESPACE_STD’
/usr/include/stdio.h:771: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘ftello’
/usr/include/stdio.h:785: error: expected declaration specifiers before ‘__BEGIN_NAMESPACE_STD’
/usr/include/stdio.h:796: error: expected ‘)’ before ‘*’ token
/usr/include/stdio.h:808: error: expected declaration specifiers before ‘__END_NAMESPACE_STD’
/usr/include/stdio.h:821: error: expected ‘)’ before ‘*’ token
/usr/include/stdio.h:823: error: expected ‘)’ before ‘*’ token
/usr/include/stdio.h:824: error: expected declaration specifiers before ‘__END_NAMESPACE_STD’
/usr/include/stdio.h:829: error: expected ‘)’ before ‘*’ token
/usr/include/stdio.h:830: error: expected ‘)’ before ‘*’ token
/usr/include/stdio.h:834: error: expected declaration specifiers before ‘__BEGIN_NAMESPACE_STD’
/usr/include/stdio.h:840: error: expected declaration specifiers before ‘__END_NAMESPACE_STD’
/usr/include/stdio.h:846:30: error: bits/sys_errlist.h: No such file or directory
/usr/include/stdio.h:856: error: expected ‘)’ before ‘*’ token
/usr/include/stdio.h:866: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
/usr/include/stdio.h:872: error: expected ‘)’ before ‘*’ token
/usr/include/stdio.h:878: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__THROW’
/usr/include/stdio.h:906: error: expected ‘)’ before ‘*’ token
/usr/include/stdio.h:910: error: expected ‘)’ before ‘*’ token
/usr/include/stdio.h:913: error: expected ‘)’ before ‘*’ token
/usr/include/stdio.h:936: error: expected declaration specifiers before ‘__END_DECLS’
helloworld.c:10: error: old-style parameter declarations in prototyped function definition
helloworld.c:10: error: expected ‘{’ at end of input
Run Code Online (Sandbox Code Playgroud)

FWIW,我正在运行Ubuntu 11.10; 一个相当新的安装.我认为在安装时我没有做过什么,但我之前从未遇到过这个问题.我将不胜感激任何建议,并且可以回答您可能提出的任何问题,以帮助我澄清/缩小问题范围.再次感谢!

编辑:谢谢你的建议,伙计们,但我仍然迷路了.我已经卸载/重新安装了libc-dev-bin,libc6-dev,gcc和dpkg.我建议我问包管理器crt1.o和crti.o在哪里,但我担心我不知道怎么做.

有没有一种万无一失的蛮力方式来完全重建所有库和头文件,而不是重新安装Ubuntu?如果没有,我可能会决定重新安装.

Dal*_*und 8

您几乎必须有一组损坏的头文件.要确认,请尝试以下操作:

extern int printf(char *, ...);
int main() {
    printf("hello world!\n");
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

如果这个编译干净,stdio.h它包含的某些文件或其中一个文件已损坏.如果输出二进制文件运行并产生预期的输出,那么乍一看库本身看起来还不错.