gpt4 book ai didi

c++ - 在我的 Mac 上编译时,当我使用 "gcc"编译但不使用 clang++ 时出现此错误

转载 作者:行者123 更新时间:2023-11-30 01:43:52 25 4
gpt4 key购买 nike

当我尝试在 Mac 上编译我的 C++ 代码时出现此错误。我已经在 PC 上编程了一段时间,但刚得到一台用于 UNI 工作的 Mac 笔记本电脑,我已经习惯了。我通常使用“gcc”编译,但它似乎不起作用。任何帮助,将不胜感激。在那之前,我只会在编译时使用“clang++”。

或者,如果我使用“gcc”编译并且代码中有错误,它也可以完美运行。只有在没有错误时才会发生这种情况。

Michaels-MacBook-Pro:C++ Michael$ cc HelloWorld.cpp 
Undefined symbols for architecture x86_64:
"std::__1::locale::use_facet(std::__1::locale::id&) const", referenced from:
std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::__put_character_sequence<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*, unsigned long) in HelloWorld-97feed.o
"std::__1::ios_base::getloc() const", referenced from:
std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::__put_character_sequence<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*, unsigned long) in HelloWorld-97feed.o
"std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::__init(unsigned long, char)", referenced from:
std::__1::ostreambuf_iterator<char, std::__1::char_traits<char> > std::__1::__pad_and_output<char, std::__1::char_traits<char> >(std::__1::ostreambuf_iterator<char, std::__1::char_traits<char> >, char const*, char const*, char const*, std::__1::ios_base&, char) in HelloWorld-97feed.o
"std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::~basic_string()", referenced from:
std::__1::ostreambuf_iterator<char, std::__1::char_traits<char> > std::__1::__pad_and_output<char, std::__1::char_traits<char> >(std::__1::ostreambuf_iterator<char, std::__1::char_traits<char> >, char const*, char const*, char const*, std::__1::ios_base&, char) in HelloWorld-97feed.o
"std::__1::basic_ostream<char, std::__1::char_traits<char> >::sentry::sentry(std::__1::basic_ostream<char, std::__1::char_traits<char> >&)", referenced from:
std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::__put_character_sequence<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*, unsigned long) in HelloWorld-97feed.o
"std::__1::basic_ostream<char, std::__1::char_traits<char> >::sentry::~sentry()", referenced from:
std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::__put_character_sequence<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*, unsigned long) in HelloWorld-97feed.o
"std::__1::cout", referenced from:
_main in HelloWorld-97feed.o
"std::__1::ctype<char>::id", referenced from:
std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::__put_character_sequence<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*, unsigned long) in HelloWorld-97feed.o
"std::__1::locale::~locale()", referenced from:
std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::__put_character_sequence<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*, unsigned long) in HelloWorld-97feed.o
"std::__1::ios_base::__set_badbit_and_consider_rethrow()", referenced from:
std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::__put_character_sequence<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*, unsigned long) in HelloWorld-97feed.o
"std::__1::ios_base::clear(unsigned int)", referenced from:
std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::__put_character_sequence<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*, unsigned long) in HelloWorld-97feed.o
"std::terminate()", referenced from:
___clang_call_terminate in HelloWorld-97feed.o
"___cxa_begin_catch", referenced from:
std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::__put_character_sequence<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*, unsigned long) in HelloWorld-97feed.o
___clang_call_terminate in HelloWorld-97feed.o
"___cxa_end_catch", referenced from:
std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::__put_character_sequence<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*, unsigned long) in HelloWorld-97feed.o
"___gxx_personality_v0", referenced from:
std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::__put_character_sequence<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*, unsigned long) in HelloWorld-97feed.o
std::__1::ostreambuf_iterator<char, std::__1::char_traits<char> > std::__1::__pad_and_output<char, std::__1::char_traits<char> >(std::__1::ostreambuf_iterator<char, std::__1::char_traits<char> >, char const*, char const*, char const*, std::__1::ios_base&, char) in HelloWorld-97feed.o
Dwarf Exception Unwind Info (__eh_frame) in HelloWorld-97feed.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

最佳答案

gccclangcc(在您的系统上似乎是 clang 的符号链接(symbolic link))是构建 C 程序的命令。

g++clang++ 是构建 C++ 程序的命令。

C 和 C++ 是两种不同的语言。

虽然所有这些命令通常只是幕后更大的编译器的“前门”,它能够构建各种东西,但有一些默认值取决于您输入的实际命令。例如,执行 gcccc 不会自动将 C++ 标准库添加到链接到您的程序的库中。

阅读文档,然后使用正确的命令在您的工具链中构建 C++ 程序。对于 Clang,这是 clang++(如您所见)。对于 GCC,这是 g++

关于c++ - 在我的 Mac 上编译时,当我使用 "gcc"编译但不使用 clang++ 时出现此错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37100803/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com