我刚刚切换到基本操作系统并安装了 sublime 文本编辑器。我用 C++ 编写了一个基本的 hello world 程序来检查工作。我得到这个错误。
/tmp/cc3Pmvft.o: In function `main':
source.cpp:(.text+0xa): undefined reference to `std::cout'
source.cpp:(.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*)'
source.cpp:(.text+0x14): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)'
source.cpp:(.text+0x1c): undefined reference to `std::ostream::operator<<(std::ostream& (*)(std::ostream&))'
/tmp/cc3Pmvft.o: In function `__static_initialization_and_destruction_0(int, int)':
source.cpp:(.text+0x4a): undefined reference to `std::ios_base::Init::Init()'
source.cpp:(.text+0x59): undefined reference to `std::ios_base::Init::~Init()'
collect2: error: ld returned 1 exit status
hello world 程序是,
#include <iostream>
using namespace std;
int main(){
cout << "Hello World!" << endl;
return 0;
}
我在 google 和 stackoverflow 中搜索了答案,但找不到解决方案。