PDA

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



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

#include<iostream>

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!

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


ought to do it...

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

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

hod139
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