View Full Version : What do I need to compile a cpp file?

April 4th, 2006, 07:43 AM
My source code is faily simple as below:


using namespace std;

int main(void)
cout<<"Hello World!"<<endl;
return 0;

But compiler gave me some error messages like this:
/tmp/ccNfUm8H.o: In function `main':
1.cpp:(.text+0x25): undefined reference to `std::cout'
1.cpp:(.text+0x2a): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'

I used cpp to compile my code, is it the right thing to compile C++ files?
thx a lot!

April 4th, 2006, 08:32 AM
gcc <filename> -lstdc++

ought to do it...

April 4th, 2006, 10:15 AM
you can also try
g++ <filename>

April 4th, 2006, 12:55 PM
god....can't start X now....

April 4th, 2006, 10:30 PM
Can't help you with X, but to compile make sure you have build-essential installed

sudo apt-get install build-essential
and then simply type

g++ file.cpp