I'm trying to compile a C++ helloWorld in terminal.
#include <iostream>
using namespace std;
int main() {
cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
return 0;
}
I cd to the directory containing the code. I manage to compile with the command g++ -o hello c_helloworld.cpp. But when I use the command gcc -o hello c_helloworld.cpp I get the following error.
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)