Ubuntu编译C++报错‘std::cout’未定义的引用

whs@whs-virtual-machine:~/test$ gcc task2.cpp -o task2
/tmp/cctLrA5c.o:在函数‘main’中:
task2.cpp:(.text+0x21):对‘std::cout’未定义的引用
task2.cpp:(.text+0x26):对‘std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)’未定义的引用
task2.cpp:(.text+0x30):对‘std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)’未定义的引用
task2.cpp:(.text+0x3b):对‘std::ostream::operator<<(std::ostream& (*)(std::ostream&))’未定义的引用
task2.cpp:(.text+0x49):对‘std::cin’未定义的引用
task2.cpp:(.text+0x4e):对‘std::istream::operator>>(int&)’未定义的引用
task2.cpp:(.text+0x7e):对‘std::cout’未定义的引用
task2.cpp:(.text+0x83):对‘std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)’未定义的引用
task2.cpp:(.text+0x93):对‘std::ostream::operator<<(int)’未定义的引用
task2.cpp:(.text+0x9d):对‘std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)’未定义的引用
task2.cpp:(.text+0xa8):对‘std::ostream::operator<<(std::ostream& (*)(std::ostream&))’未定义的引用
/tmp/cctLrA5c.o:在函数‘__static_initialization_and_destruction_0(int, int)’中:
task2.cpp:(.text+0xec):对‘std::ios_base::Init::Init()’未定义的引用
task2.cpp:(.text+0x101):对‘std::ios_base::Init::~Init()’未定义的引用
collect2: error: ld returned 1 exit status

使用g++命令:

g++ task2.cpp -o task2
已标记关键词 清除标记
©️2020 CSDN 皮肤主题: Age of Ai 设计师:meimeiellie 返回首页