【发布时间】:2019-09-29 11:56:55
【问题描述】:
我正在尝试在终端中编译一个 C++ helloWorld。
#include <iostream>
using namespace std;
int main() {
cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
return 0;
}
我 cd 到包含代码的目录。我设法使用命令 g++ -o hello c_helloworld.cpp 进行编译。但是当我使用命令 gcc -o hello c_helloworld.cpp 我得到以下错误。
架构 x86_64 的未定义符号:“std::__1::locale::use_facet(std::__1::locale::id&) const”,引用 从: std::__1::ctype const& std::__1::use_facet >(std::__1::locale const&) 在 c_helloworld-a3d3b8.o "std::__1::ios_base::getloc() const", 参考自: std::__1::basic_ios >::widen(char) const in c_helloworld-a3d3b8.o "std::__1::basic_string, std::__1::allocator >::__init(unsigned long, char)",引用 从: std::__1::basic_string, std::__1::allocator >::basic_string(unsigned long, char) in c_helloworld-a3d3b8.o "std::__1::basic_string, std::__1::allocator ::~basic_string()",引用自: std::__1::ostreambuf_iterator > std::__1::__pad_and_output >(std::__1::ostreambuf_iterator >, char const*, char const*, char const*, std::__1::ios_base&, char) in c_helloworld-a3d3b8.o "std::__1::basic_ostream >::put(char)",引用自: std::__1::basic_ostream >& std::__1::endl (std::__1::basic_ostream >&) 在 c_helloworld-a3d3b8.o "std::__1::basic_ostream >::flush()",引用自: std::__1::basic_ostream >& std::__1::endl (std::__1::basic_ostream >&) 在 c_helloworld-a3d3b8.o "std::__1::basic_ostream ::sentry::sentry(std::__1::basic_ostream >&)”,引用自: std::__1::basic_ostream >& std::__1::__put_character_sequence (std::__1::basic_ostream >&, char const*, unsigned long) 在 c_helloworld-a3d3b8.o
“std::__1::basic_ostream ::sentry::~sentry()”,引用自: std::__1::basic_ostream >& std::__1::__put_character_sequence (std::__1::basic_ostream >&, char const*, unsigned long) 在 c_helloworld-a3d3b8.o "std::__1::cout", 参考自: _main in c_helloworld-a3d3b8.o "std::__1::ctype::id",引用自: std::__1::ctype const& std::__1::use_facet >(std::__1::locale const&) 在 c_helloworld-a3d3b8.o "std::__1::locale::~locale()" 中,引用 从: std::__1::basic_ios >::widen(char) const in c_helloworld-a3d3b8.o "std::__1::ios_base::__set_badbit_and_consider_rethrow()",引用 从: std::__1::basic_ostream >& std::__1::__put_character_sequence (std::__1::basic_ostream >&, char const*, unsigned long) 在 c_helloworld-a3d3b8.o
“std::__1::ios_base::clear(unsigned int)”,引用自: c_helloworld-a3d3b8.o "std::terminate()" 中的 std::__1::ios_base::setstate(unsigned int),引用自: c_helloworld-a3d3b8.o "___cxa_begin_catch" 中的___clang_call_terminate,引用自: std::__1::basic_ostream >& std::__1::__put_character_sequence (std::__1::basic_ostream >&, char const*, unsigned long) 在 c_helloworld-a3d3b8.o ___clang_call_terminate in c_helloworld-a3d3b8.o "___cxa_call_unexpected",引用自: std::__1::ostreambuf_iterator >::ostreambuf_iterator(std::__1::basic_ostream >&) 在 c_helloworld-a3d3b8.o
“___cxa_end_catch”,引用自: std::__1::basic_ostream >& std::__1::__put_character_sequence (std::__1::basic_ostream >&, char const*, unsigned long) 在 c_helloworld-a3d3b8.o
“___gxx_personality_v0”,引用自: std::__1::basic_ostream >& std::__1::__put_character_sequence (std::__1::basic_ostream >&, char const*, unsigned long) 在 c_helloworld-a3d3b8.o std::__1::ostreambuf_iterator > std::__1::__pad_and_output >(std::__1::ostreambuf_iterator >, char const*, char const*, char const*, std::__1::ios_base&, char) in c_helloworld-a3d3b8.o c_helloworld-a3d3b8.o 中的 std::__1::ostreambuf_iterator >::ostreambuf_iterator(std::__1::basic_ostream >&) c_helloworld-a3d3b8.o 中的 std::__1::basic_ios >::widen(char) const c_helloworld-a3d3b8.o ld 中的 Dwarf 异常展开信息 (__eh_frame):未找到架构 x86_64 的符号 clang:错误:链接器命令失败,退出代码为 1(使用 -v 查看 调用)
【问题讨论】: