This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
compiler problems pt2
- From: robert watson <reswatson at yahoo dot com>
- To: gcc-help at gcc dot gnu dot org
- Date: Fri, 2 Jan 2009 09:01:23 -0800 (PST)
- Subject: compiler problems pt2
- Reply-to: reswatson at yahoo dot com
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.)