compiler problems pt2
robert watson
reswatson@yahoo.com
Fri Jan 2 17:02:00 GMT 2009
Hi Gnu folks,
Thanks for the replies. Compiling my code using:
cd Desktop
g++ /home/robert/Desktop/test.c # uses c++ compiler
Instead of:
cd Desktop
gcc /home/robert/Desktop/test.c # uses c++ compiler
Produced no errors, and an output file called 'a.out', so I guess that means g++ keeps tabs on the libraries better.
I would never have tried that myself, so some sort of explanation for all this stuff in the manual would be really useful to others. After all 'HelloWorld' programs are supposed to be easy!!
BTW How do I run the code? Double clicking doesn't work. I mean it's like clicking the desktop - absolutely nothing happens.
Thanks again,
Rob
My code:
/* my second program in C++
with more comments */
#include <iostream>
#include <string>
using namespace std;
int main ()
{
cout << "Hello World! "; // prints Hello World!
cout << "I'm a C++ program"; // prints I'm a C++ program
return 0;
}
The errors I got with g++:
robert@robert-laptop:~$ gcc /home/robert/Desktop/test.c # uses c++ compiler
/home/robert/Desktop/test.c:4:20: error: iostream: No such file or directory
/home/robert/Desktop/test.c:5:18: error: string: No such file or directory
/home/robert/Desktop/test.c:6: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘namespace’
/home/robert/Desktop/test.c: In function ‘main’:
/home/robert/Desktop/test.c:10: error: ‘cout’ undeclared (first use in this function)
/home/robert/Desktop/test.c:10: error: (Each undeclared identifier is reported only once
/home/robert/Desktop/test.c:10: error: for each function it appears in.)
More information about the Gcc-help
mailing list