4

我相信我正在处理某种损坏的图书馆。我写了以下代码:

//helloworld.c                                                                  

#include <stdio.h>

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

  return 0;
}

并使用以下命令编译它:

gcc helloworld.c

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

/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

FWIW,我正在运行 Ubuntu 11.10;一个相当新的安装。我想在安装时我没有做一些事情,但我以前从未遇到过这个问题。我将不胜感激任何建议,并且可以回答您可能需要帮助我澄清/缩小问题的任何问题。再次感谢!

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

除了重新安装 Ubuntu 之外,是否有一种万无一失的蛮力方法来完全重建所有库和头文件?如果没有,我可能会决定重新安装。

4

1 回答 1

8

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

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

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

于 2012-02-28T18:07:37.523 回答