gpt4 book ai didi

c++ - 在终端中编译 hello world.cpp (macOS)

转载 作者:行者123 更新时间:2023-11-28 01:21:22 26 4
gpt4 key购买 nike

<分区>

我正在尝试在终端中编译 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 时,出现以下错误。

Undefined symbols for architecture x86_64: "std::__1::locale::use_facet(std::__1::locale::id&) const", referenced from: std::__1::ctype const& std::__1::use_facet >(std::__1::locale const&) in c_helloworld-a3d3b8.o "std::__1::ios_base::getloc() const", referenced from: std::__1::basic_ios >::widen(char) const in c_helloworld-a3d3b8.o "std::__1::basic_string, std::__1::allocator >::__init(unsigned long, char)", referenced from: 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()", referenced from: 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)", referenced from: std::__1::basic_ostream >& std::__1::endl (std::__1::basic_ostream >&) in c_helloworld-a3d3b8.o "std::__1::basic_ostream >::flush()", referenced from: std::__1::basic_ostream >& std::__1::endl (std::__1::basic_ostream >&) in c_helloworld-a3d3b8.o "std::__1::basic_ostream ::sentry::sentry(std::__1::basic_ostream >&)", referenced from: std::__1::basic_ostream >& std::__1::__put_character_sequence (std::__1::basic_ostream >&, char const*, unsigned long) in c_helloworld-a3d3b8.o
"std::__1::basic_ostream ::sentry::~sentry()", referenced from: std::__1::basic_ostream >& std::__1::__put_character_sequence (std::__1::basic_ostream >&, char const*, unsigned long) in c_helloworld-a3d3b8.o "std::__1::cout", referenced from: _main in c_helloworld-a3d3b8.o "std::__1::ctype::id", referenced from: std::__1::ctype const& std::__1::use_facet >(std::__1::locale const&) in c_helloworld-a3d3b8.o "std::__1::locale::~locale()", referenced from: std::__1::basic_ios >::widen(char) const in c_helloworld-a3d3b8.o "std::__1::ios_base::__set_badbit_and_consider_rethrow()", referenced from: std::__1::basic_ostream >& std::__1::__put_character_sequence (std::__1::basic_ostream >&, char const*, unsigned long) in c_helloworld-a3d3b8.o
"std::__1::ios_base::clear(unsigned int)", referenced from: std::__1::ios_base::setstate(unsigned int) in c_helloworld-a3d3b8.o "std::terminate()", referenced from: ___clang_call_terminate in c_helloworld-a3d3b8.o "___cxa_begin_catch", referenced from: std::__1::basic_ostream >& std::__1::__put_character_sequence (std::__1::basic_ostream >&, char const*, unsigned long) in c_helloworld-a3d3b8.o ___clang_call_terminate in c_helloworld-a3d3b8.o "___cxa_call_unexpected", referenced from: std::__1::ostreambuf_iterator >::ostreambuf_iterator(std::__1::basic_ostream >&) in c_helloworld-a3d3b8.o
"___cxa_end_catch", referenced from: std::__1::basic_ostream >& std::__1::__put_character_sequence (std::__1::basic_ostream >&, char const*, unsigned long) in c_helloworld-a3d3b8.o
"___gxx_personality_v0", referenced from: std::__1::basic_ostream >& std::__1::__put_character_sequence (std::__1::basic_ostream >&, char const*, unsigned long) in 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 std::__1::ostreambuf_iterator >::ostreambuf_iterator(std::__1::basic_ostream >&) in c_helloworld-a3d3b8.o std::__1::basic_ios >::widen(char) const in c_helloworld-a3d3b8.o Dwarf Exception Unwind Info (__eh_frame) in c_helloworld-a3d3b8.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

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