View Full Version : "Hello world" won't compile in gcc


aneeshm
Jun 29, 2004, 12:39 AM
I'm currently using gcc on RHEL WS v3(Taroon) , and I can't get it to work compile Hello World" .

The program follows .

#include<iostream>

using namespace std;

int main()
{
cout<<"\nHello World";
}


GCC outputs :

In function int main
undefined reference to cout
Use the function first

or something similar .

Any help ?

ainwood
Jun 29, 2004, 12:46 AM
I'm no C programmer, (and I'm sure one who actually knows what (s)he's talking about will come by shortly, but don't you need a return value (eg return 0)

Also, try some spaces between the characters.

aneeshm
Jun 29, 2004, 12:56 AM
I'll try returning . Anything else ?

kcwong
Jun 29, 2004, 03:30 AM
The compiler said it doesn't know what is "cout".

You can't use C++ stuff just like that with gcc - it's for compiling C, not C++. If you want to stick with C++, use another compiler - e.g. g++.

Or you can simply change the code and use stdio.h and printf instead.

Google groups search for "cout gcc" for more information.

Comraddict
Jun 29, 2004, 08:55 PM
..and isn't "\n" supposed to go after hello world?

also it is iostream.h not iostream

nihilistic
Jun 29, 2004, 09:06 PM
#include<stdio.h>

int main()
{
printf("\nHello World!\n");
return 0;
}


// Most Modern compilers will also accept

#include<stdio.h>
void main(){printf("\nHello World!\n");}

GenghisK
Jun 30, 2004, 04:59 AM
IMHO, cout would require the library called conio.h (console i/o)
Actually I always automatically put conio et stdio since they are almost always required.