Cannot compile with gcc

Hi Everyone,

I am having a bit of a trouble with gcc. I wrote a simple Hello World C++ program:

#include <iostream>

int main()
{
cout<<“Hello World”;
return 0;
}

When I tried to compile this using gcc. I got a long list of errors:

/usr/include/ctype.h:52: error: stray ‘\370’ in program
/usr/include/ctype.h:52: error: stray ‘`’ in program
/usr/include/ctype.h:52: error: stray ‘\216’ in program
/usr/include/ctype.h:52: error: stray ‘\10’ in program
/usr/include/ctype.h:52: error: stray ‘\4’ in program
/usr/include/ctype.h:52: error: stray ‘\20’ in program
/usr/include/ctype.h:52: error: stray ‘\215’ in program
/usr/include/ctype.h:52: error: stray ‘\10’ in program
/usr/include/ctype.h:52: error: stray ‘\215’ in program
/usr/include/ctype.h:52: error: stray ‘\350’ in program
/usr/include/ctype.h:52: error: stray ‘\323’ in program
/usr/include/ctype.h:52: error: stray ‘\201’ in program
/usr/include/ctype.h:52: error: stray ‘\1’ in program
/usr/include/ctype.h:52: error: stray ‘\205’ in program
/usr/include/ctype.h:52: error: stray ‘\300’ in program
/usr/include/ctype.h:52: error: stray ‘\7’ in program
/usr/include/ctype.h:52: error: stray ‘\270’ in program
/usr/include/ctype.h:52: error: stray ‘\1’ in program
/usr/include/ctype.h:52: error: stray ‘\353’ in program
/usr/include/ctype.h:52: error: stray ‘\2’ in program
/usr/include/ctype.h:52: error: stray ‘\300’ in program
/usr/include/ctype.h:52: error: stray ‘\215’ in program
/usr/include/ctype.h:52: error: stray ‘\350’ in program
/usr/include/ctype.h:52: error: stray ‘\211’ in program
/usr/include/ctype.h:52: error: stray ‘\354’ in program
/usr/include/ctype.h:52: error: stray ‘\303’ in program
/usr/include/ctype.h:52: error: stray ‘\215’ in program
/usr/include/ctype.h:52: error: stray ‘\266’ in program
/usr/include/ctype.h:52: error: stray ‘\215’ in program
/usr/include/ctype.h:52: error: stray ‘\274’ in program
/usr/include/ctype.h:52: error: missing terminating ’ character
/usr/include/ctype.h:53: error: stray ‘\203’ in program
/usr/include/ctype.h:53: error: stray ‘\370’ in program
/usr/include/ctype.h:53: error: stray ‘\1’ in program
/usr/include/ctype.h:53: error: stray ‘\351’ in program
/usr/include/ctype.h:53: error: stray ‘\6’ in program
/usr/include/ctype.h:53: error: stray ‘\1’ in program
/usr/include/ctype.h:53: error: stray ‘\215’ in program
/usr/include/ctype.h:53: error: stray ‘\213’ in program
/usr/include/ctype.h:53: error: stray ‘\17’ in program
/usr/include/ctype.h:53: error: stray ‘\316’ in program
/usr/include/ctype.h:53: error: stray ‘\203’ in program
/usr/include/ctype.h:53: error: stray ‘\303’ in program
/usr/include/ctype.h:53: error: stray ‘\4’ in program
/usr/include/ctype.h:53: error: stray ‘\201’ in program
/usr/include/ctype.h:53: error: stray ‘\376’ in program
/usr/include/ctype.h:53: error: stray ‘\377’ in program
/usr/include/ctype.h:53: error: stray ‘\17’ in program
/usr/include/ctype.h:53: error: stray ‘\207’ in program
/usr/include/ctype.h:53: error: stray ‘\360’ in program
/usr/include/ctype.h:53: error: stray ‘\215’ in program

:open_mouth:

I thought I might have included some invalid characters in my cpp file, but the program itself is short and there were just too many errors. So I tried cpp preprocessor.

I found that it was including a file: /usr/include/wchar.h

This file is in binary form I think (shows symbols and wierd characters) and appears to be the cause of the issue. :sarcastic:

What am I using?
openSUSE 11.0
gcc 4.3

I am rather new at all this, so any help in this regard is much appreciated. Please let me know if additional info is needed.

Thanks, Pankhraj

C++ programs should be compiled with g++, not gcc.

See ANSI C++: Standard header files

(and yes, you can compile C++ program with GCC - it will call g++)

Hi,

it looks like there are some special characters in your source file (which aren’t displayed by your editor). I recommend retype these few lines again (do not copy). I had something similar before and as far as I remember this happened when i was copying some source code from a website the source files :stuck_out_tongue:

hope this helps

Thank you all for a quick response. I will check the ANSI C++ headers and try.

I did try to re-write the code for fear of invisible characters (but to no avail)…:expressionless:

Let me do some more digging and see if I cancome up with a solution…:\ I the meantime if you think something might help me, please post it here…

Hi,

I just realized that the error comes from an included file (sorry haven’t read with full attention), so something there could be malformed. Maybe it helps to reinstall glibc-devel or check the integrity of the installed files of glibc-devel with rpm -qV glibc-devel. It’s just a guess but maybe you find the solution there.

hope this helps

Hey Thanks Monex,

I haven’t been able to do anything yesterday, was caught up in my day to day work. Will try that out tonight and post the results…

Regards.

ok for the record…!!

That did not work. I tried to reinstall gcc, unfortunately that did not resolve my problem. Uhmmm…:(, will need to take it up when I have a lot of leisure time…

Hi,

I tried to reproduce the problem but I didn’t had success on this:
I tried to compile the following code:


#include <iostream>

int main()
{
        std::cout << "Hello World" << std::endl;
        return 0;
}

(in your code above “std::” before cout was missing, so that cout was unknown for the compiler). The source file was named test.cpp. Then I simply compiled it with


g++ test.cpp

and it works without any issues. Maybe you can verify the steps and say if you are doing something different.

Hope this helps

I tried using std:: before the cout, but it did not really make any difference…

I had added a line earlier, “using namespace std”, however I changed it to reflect what you had written… unfortunately that did not help. Do you think i need to completely re-install all the gcc packages??

Hi,

maybe it helps when you can paste the complete compiler output somewhere (use pastebin - collaborative debugging tool or something else) maybe the errors come from somewhere else.

Hi Monex,

The error was a bit too big for the pastebin tool… so I redirected the stderr to a file and uploaded it here

It is available for 7 days only, but by then I should be able to get a more permanent place for things like these…

Anyway, have a look. Does it throw any clues?

Regards…!

Hi,

it looks like an encoding problem somewhere. I didn’t already had such a problem and I have no clue why this happens.

I googled a bit around and maybe setting the LANG environment variable to a different value helps. Before running g++ type “export LANG=C”.

Can you paste the output of “echo $LANG” here (before changing the LANG variable), maybe this helps to get new ideas to solve this problem.

Hi Monex,

echo $LANG gave the following result:
POSIX

I also tried g++ with LANG set as C, but still got the error…

Regards.

Hi,

I’m currently running out of ideas. Maybe reinstalling the gcc packages solves this problem. It might be an encoding issue but I have no idea what exactly goes wrong.

Hi, maybe that will resolve my issue. I will try that on a weekend. Weekdays are a bit too packed to do that…

and, btw I’d like to thank you for all the support you’ve given all this time…

Regards.

I believe this is an encoding issue. Can you copy paste the output of the command - “locale” ?

  • Thejaswi Raya

LANG=POSIX
LC_CTYPE=en_US.UTF-8
LC_NUMERIC=“POSIX”
LC_TIME=“POSIX”
LC_COLLATE=“POSIX”
LC_MONETARY=“POSIX”
LC_MESSAGES=“POSIX”
LC_PAPER=“POSIX”
LC_NAME=“POSIX”
LC_ADDRESS=“POSIX”
LC_TELEPHONE=“POSIX”
LC_MEASUREMENT=“POSIX”
LC_IDENTIFICATION=“POSIX”
LC_ALL=

is the output of Locale…