我想在C++中編譯一個簡單的Hello World程序,但我不斷收到以下錯誤...爲什麼?爲什麼我不能在C++中編譯HelloWorld?
gcc -o HelloWorldCompiled HelloWorld.cc
/tmp/ccvLW1ei.o: In function `main':
HelloWorld.cc:(.text+0xa): undefined reference to `std::cout'
HelloWorld.cc:(.text+0xf): 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*)'
/tmp/ccvLW1ei.o: In function `__static_initialization_and_destruction_0(int, int)':
HelloWorld.cc:(.text+0x3d): undefined reference to `std::ios_base::Init::Init()'
HelloWorld.cc:(.text+0x42): undefined reference to `std::ios_base::Init::~Init()'
/tmp/ccvLW1ei.o:(.eh_frame+0x12): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status
這裏是我的程序:
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World\n";
}
謝謝...有什麼區別? – 2012-01-31 22:23:34
gcc是一個C編譯器,g ++是一個C++編譯器 – AJG85 2012-01-31 22:24:55
g ++可能只是gcc的一個別名...你可以真正使用gcc來編譯C++我想通過使用'-x C++'命令行選項... – mtahmed 2012-01-31 22:25:26