应该很简单,但是当我编译 C++ Hello World 代码时会返回一堆未定义的符号错误。
// my first program in C++
#include <iostream>
using namespace std;
int main ()
{
cout << "Hello World!";
return 0;
}
下面是我的编译方式:打开终端,cd 到目录,gcc hello.cpp
然后我得到错误。有什么想法吗?我觉得我可能弄坏了一些东西......或者我只是错过了一些非常明显的东西。任何帮助是极大的赞赏!
继承人的错误:
Undefined symbols for architecture x86_64:
"std::cout", referenced from:
_main in ccfUAf5i.o
"std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)", referenced from:
_main in ccfUAf5i.o
"std::ios_base::Init::Init()", referenced from:
__static_initialization_and_destruction_0(int, int)in ccfUAf5i.o
"std::ios_base::Init::~Init()", referenced from:
___tcf_0 in ccfUAf5i.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status