当尝试用 C++ 编写代码时,我收到一长串错误,例如“/tmp/ccloHU4h.o:dad.cpp:(.text+0x5c): undefined reference to `std::cout'”
When trying to code in C++ I get a long string of errors like "/tmp/ccloHU4h.o:dad.cpp:(.text+0x5c): undefined reference to `std::cout'"
完整的错误是
/tmp/ccloHU4h.o:dad.cpp:(.text+0x28): undefined reference to `___gxx_personality _sj0'
/tmp/ccloHU4h.o:dad.cpp:(.text+0x5c): undefined reference to `std::cout'
/tmp/ccloHU4h.o:dad.cpp:(.text+0x68): 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/ccloHU4h.o:dad.cpp:(.text+0x70): undefined reference to `std::basic_ostream <char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::b asic_ostream<char, std::char_traits<char> >&)'
/tmp/ccloHU4h.o:dad.cpp:(.text+0x78): undefined reference to `std::basic_ostream <char, std::char_traits<char> >::operator<<(std::basic_ostream<char, std::char_t raits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&))'
/tmp/ccloHU4h.o:dad.cpp:(.text+0x86): undefined reference to `std::cin'
/tmp/ccloHU4h.o:dad.cpp:(.text+0x8b): undefined reference to `std::basic_istream <char, std::char_traits<char> >::operator>>(int&)'
/tmp/ccloHU4h.o:dad.cpp:(.text+0x9a): undefined reference to `std::cout'
/tmp/ccloHU4h.o:dad.cpp:(.text+0x9f): 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/ccloHU4h.o:dad.cpp:(.text+0xa7): undefined reference to `std::basic_ostream <char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::b asic_ostream<char, std::char_traits<char> >&)'
/tmp/ccloHU4h.o:dad.cpp:(.text+0xaf): undefined reference to `std::basic_ostream <char, std::char_traits<char> >::operator<<(std::basic_ostream<char, std::char_t raits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&))'
/tmp/ccloHU4h.o:dad.cpp:(.text+0xba): undefined reference to `std::__cxx11::basi c_string<char, std::char_traits<char>, std::allocator<char> >::basic_string()'
/tmp/ccloHU4h.o:dad.cpp:(.text+0xc8): undefined reference to `std::cin'
/tmp/ccloHU4h.o:dad.cpp:(.text+0xd4): undefined reference to `std::basic_istream <char, std::char_traits<char> >& std::operator>><char, std::char_traits<char>, s td::allocator<char> >(std::basic_istream<char, std::char_traits<char> >&, std::_ _cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&)'
/tmp/ccloHU4h.o:dad.cpp:(.text+0xe2): undefined reference to `std::cout'
/tmp/ccloHU4h.o:dad.cpp:(.text+0xe7): undefined reference to `std::basic_ostream <char, std::char_traits<char> >& std::operator<< <char, std::char_traits<char>, std::allocator<char> >(std::basic_ostream<char, std::char_traits<char> >&, std:: __cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const &)'
/tmp/ccloHU4h.o:dad.cpp:(.text+0xf7): 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/ccloHU4h.o:dad.cpp:(.text+0x108): undefined reference to `std::basic_ostrea m<char, std::char_traits<char> >& std::operator<< <char, std::char_traits<char>, std::allocator<char> >(std::basic_ostream<char, std::char_traits<char> >&, std: :__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > cons t&)'
/tmp/ccloHU4h.o:dad.cpp:(.text+0x118): undefined reference to `std::basic_ostrea m<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std: :basic_ostream<char, std::char_traits<char> >&, char const*)'
/tmp/ccloHU4h.o:dad.cpp:(.text+0x120): undefined reference to `std::basic_ostrea m<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std:: basic_ostream<char, std::char_traits<char> >&)'
/tmp/ccloHU4h.o:dad.cpp:(.text+0x128): undefined reference to `std::basic_ostrea m<char, std::char_traits<char> >::operator<<(std::basic_ostream<char, std::char_ traits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&))'
/tmp/ccloHU4h.o:dad.cpp:(.text+0x13a): undefined reference to `std::__cxx11::bas ic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
/tmp/ccloHU4h.o:dad.cpp:(.text+0x156): undefined reference to `std::__cxx11::bas ic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
/tmp/ccloHU4h.o:dad.cpp:(.text+0x19f): undefined reference to `std::ios_base::In it::Init()'
/tmp/ccloHU4h.o:dad.cpp:(.text+0x1b6): undefined reference to `std::ios_base::In it::~Init()'
collect2: error: ld returned 1 exit status
使用 gcc 并输入 gcc "file name" -o "file name without .cpp" 时会发生这种情况
我有
#include <iostream>
#include <string>
using namespace std;
包含在代码中。
另外我对编码很陌生,所以如果它是一个简单的问题,请不要认为这是一个笑话。我真的需要帮助。
您需要 link 和 g++
,而不是 gcc
。 gcc
编译器驱动程序将编译 C++ 源代码,但它将 link 它们仅与 C 标准库一起使用,因此许多仅限 C++ 的功能将不起作用。
完整的错误是
/tmp/ccloHU4h.o:dad.cpp:(.text+0x28): undefined reference to `___gxx_personality _sj0'
/tmp/ccloHU4h.o:dad.cpp:(.text+0x5c): undefined reference to `std::cout'
/tmp/ccloHU4h.o:dad.cpp:(.text+0x68): 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/ccloHU4h.o:dad.cpp:(.text+0x70): undefined reference to `std::basic_ostream <char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::b asic_ostream<char, std::char_traits<char> >&)'
/tmp/ccloHU4h.o:dad.cpp:(.text+0x78): undefined reference to `std::basic_ostream <char, std::char_traits<char> >::operator<<(std::basic_ostream<char, std::char_t raits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&))'
/tmp/ccloHU4h.o:dad.cpp:(.text+0x86): undefined reference to `std::cin'
/tmp/ccloHU4h.o:dad.cpp:(.text+0x8b): undefined reference to `std::basic_istream <char, std::char_traits<char> >::operator>>(int&)'
/tmp/ccloHU4h.o:dad.cpp:(.text+0x9a): undefined reference to `std::cout'
/tmp/ccloHU4h.o:dad.cpp:(.text+0x9f): 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/ccloHU4h.o:dad.cpp:(.text+0xa7): undefined reference to `std::basic_ostream <char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::b asic_ostream<char, std::char_traits<char> >&)'
/tmp/ccloHU4h.o:dad.cpp:(.text+0xaf): undefined reference to `std::basic_ostream <char, std::char_traits<char> >::operator<<(std::basic_ostream<char, std::char_t raits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&))'
/tmp/ccloHU4h.o:dad.cpp:(.text+0xba): undefined reference to `std::__cxx11::basi c_string<char, std::char_traits<char>, std::allocator<char> >::basic_string()'
/tmp/ccloHU4h.o:dad.cpp:(.text+0xc8): undefined reference to `std::cin'
/tmp/ccloHU4h.o:dad.cpp:(.text+0xd4): undefined reference to `std::basic_istream <char, std::char_traits<char> >& std::operator>><char, std::char_traits<char>, s td::allocator<char> >(std::basic_istream<char, std::char_traits<char> >&, std::_ _cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&)'
/tmp/ccloHU4h.o:dad.cpp:(.text+0xe2): undefined reference to `std::cout'
/tmp/ccloHU4h.o:dad.cpp:(.text+0xe7): undefined reference to `std::basic_ostream <char, std::char_traits<char> >& std::operator<< <char, std::char_traits<char>, std::allocator<char> >(std::basic_ostream<char, std::char_traits<char> >&, std:: __cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const &)'
/tmp/ccloHU4h.o:dad.cpp:(.text+0xf7): 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/ccloHU4h.o:dad.cpp:(.text+0x108): undefined reference to `std::basic_ostrea m<char, std::char_traits<char> >& std::operator<< <char, std::char_traits<char>, std::allocator<char> >(std::basic_ostream<char, std::char_traits<char> >&, std: :__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > cons t&)'
/tmp/ccloHU4h.o:dad.cpp:(.text+0x118): undefined reference to `std::basic_ostrea m<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std: :basic_ostream<char, std::char_traits<char> >&, char const*)'
/tmp/ccloHU4h.o:dad.cpp:(.text+0x120): undefined reference to `std::basic_ostrea m<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std:: basic_ostream<char, std::char_traits<char> >&)'
/tmp/ccloHU4h.o:dad.cpp:(.text+0x128): undefined reference to `std::basic_ostrea m<char, std::char_traits<char> >::operator<<(std::basic_ostream<char, std::char_ traits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&))'
/tmp/ccloHU4h.o:dad.cpp:(.text+0x13a): undefined reference to `std::__cxx11::bas ic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
/tmp/ccloHU4h.o:dad.cpp:(.text+0x156): undefined reference to `std::__cxx11::bas ic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
/tmp/ccloHU4h.o:dad.cpp:(.text+0x19f): undefined reference to `std::ios_base::In it::Init()'
/tmp/ccloHU4h.o:dad.cpp:(.text+0x1b6): undefined reference to `std::ios_base::In it::~Init()'
collect2: error: ld returned 1 exit status
使用 gcc 并输入 gcc "file name" -o "file name without .cpp" 时会发生这种情况 我有
#include <iostream>
#include <string>
using namespace std;
包含在代码中。
另外我对编码很陌生,所以如果它是一个简单的问题,请不要认为这是一个笑话。我真的需要帮助。
您需要 link 和 g++
,而不是 gcc
。 gcc
编译器驱动程序将编译 C++ 源代码,但它将 link 它们仅与 C 标准库一起使用,因此许多仅限 C++ 的功能将不起作用。