Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

helloworld.c fails to compile with 100+ errors

I believe I am dealing with some kind of corrupted library. I wrote the following code:

//helloworld.c                                                                  

#include <stdio.h>

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

  return 0;
}

And compiled it with the following command:

gcc helloworld.c

The errors I got were many. Here is a sample:

/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, I'm running Ubuntu 11.10; a fairly recent install. I presume there was something I failed to do when installing, but I have never had this problem before. I would appreciate any advice, and can answer any questions you may have to help me clarify/narrow down the problem. Thanks again!

EDIT: Thanks for your advice, folks, but I am still lost. I've uninstalled/reinstalled libc-dev-bin, libc6-dev, gcc and dpkg. It's been recommended that I ask the package manager where crt1.o and crti.o are, but I'm afraid I don't know how to do this.

Is there a surefire, brute-force way to completely rebuild all the libraries and headers, short of reinstalling Ubuntu? If there isn't, I may just decide to reinstall.

like image 447
Frank Harris Avatar asked Feb 22 '23 07:02

Frank Harris


1 Answers

You almost have to have a broken set of header files. To confirm, try the following:

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

If this compiles cleanly, somehow stdio.h or one of the files it includes has become corrupted. If the output binary runs and produces the expected output, then at a first glance the libraries themselves would look ok.

like image 183
Dale Hagglund Avatar answered Mar 02 '23 22:03

Dale Hagglund