可能重复:
GCC 链接器找不到标准库?
我正试图弄乱我在假期买的这本 C++ 书,我对 python 的理解有限,所以这些东西对我来说真的很奇怪。
我将第一节课中的这段代码输入到我的文本编辑器中,并将其保存为 .cpp 文件。
#include <iostream>
int main()
{
std::cout << "Enter two numbers:" << std::endl;
int v1 = 0, v2 = 0;
std::cin >> v1 >> v2;
std::cout << "The sum of " << v1 << " and " << v2
<< " is " << v1 + v2 << std::endl;
return 0;
}
但是当我尝试编译它时,我的终端给出了这个疯狂的输出,这是怎么回事?
Raymond-Weisss-MacBook-Pro:c++ Raylug$ gcc prog2.cpp
Undefined symbols for architecture x86_64:
"std::basic_istream<char, std::char_traits<char> >::operator>>(int&)", referenced from:
_main in cckdLEun.o
"std::basic_ostream<char, std::char_traits<char> >::operator<<(std::basic_ostream<char, std::char_traits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&))", referenced from:
_main in cckdLEun.o
"std::basic_ostream<char, std::char_traits<char> >::operator<<(int)", referenced from:
_main in cckdLEun.o
"std::ios_base::Init::Init()", referenced from:
__static_initialization_and_destruction_0(int, int)in cckdLEun.o
"std::ios_base::Init::~Init()", referenced from:
___tcf_0 in cckdLEun.o
"std::cin", referenced from:
_main in cckdLEun.o
"std::cout", referenced from:
_main in cckdLEun.o
"std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)", referenced from:
_main in cckdLEun.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 cckdLEun.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
Raymond-Weisss-MacBook-Pro:c++ Raylug$