I am using MacBook Air M2, and I am new this machine. I found out that there is clang in MacBook which is directly taken in use by default for C and C++ code in MacBook. But my system is having one issue or kind of issue, when I compile code with simple line like
gcc 1931D.cpp -o 1931D
it gives me error like:
Undefined symbols for architecture arm64:
"std::logic_error::logic_error(char const*)", referenced from:
std::length_error::length_error[abi:ue170006](char const*) in 1931D-f28fab.o
"std::length_error::~length_error()", referenced from:
std::__1::__throw_length_error[abi:ue170006](char const*) in 1931D-f28fab.o
"std::bad_array_new_length::bad_array_new_length()", referenced from:
std::__throw_bad_array_new_length[abi:ue170006]() in 1931D-f28fab.o
"std::bad_array_new_length::~bad_array_new_length()", referenced from:
std::__throw_bad_array_new_length[abi:ue170006]() in 1931D-f28fab.o
"std::__1::basic_istream<char, std::__1::char_traits<char>>::operator>>(long long&)", referenced from:
_main in 1931D-f28fab.o
solve() in 1931D-f28fab.o
solve() in 1931D-f28fab.o
solve() in 1931D-f28fab.o
solve() in 1931D-f28fab.o
"std::__1::cin", referenced from:
_main in 1931D-f28fab.o
solve() in 1931D-f28fab.o
solve() in 1931D-f28fab.o
"std::terminate()", referenced from:
___clang_call_terminate in 1931D-f28fab.o
"typeinfo for std::length_error", referenced from:
std::__1::__throw_length_error[abi:ue170006](char const*) in 1931D-f28fab.o
"typeinfo for std::bad_array_new_length", referenced from:
std::__throw_bad_array_new_length[abi:ue170006]() in 1931D-f28fab.o
"vtable for std::length_error", referenced from:
std::length_error::length_error[abi:ue170006](char const*) in 1931D-f28fab.o
NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
"operator delete(void*)", referenced from:
std::__1::allocator<long long>::deallocate[abi:ue170006](long long*, unsigned long) in 1931D-f28fab.o
void std::__1::__libcpp_operator_delete[abi:ue170006]<void*>(void*) in 1931D-f28fab.o
"operator new(unsigned long)", referenced from:
std::__1::allocator<long long>::allocate[abi:ue170006](unsigned long) in 1931D-f28fab.o
void* std::__1::__libcpp_operator_new[abi:ue170006]<unsigned long>(unsigned long) in 1931D-f28fab.o
"___cxa_allocate_exception", referenced from:
std::__1::__throw_length_error[abi:ue170006](char const*) in 1931D-f28fab.o
std::__throw_bad_array_new_length[abi:ue170006]() in 1931D-f28fab.o
"___cxa_begin_catch", referenced from:
___clang_call_terminate in 1931D-f28fab.o
"___cxa_call_unexpected", referenced from:
std::__1::vector<long long, std::__1::allocator<long long>>::max_size() const in 1931D-f28fab.o
std::__1::vector<long long, std::__1::allocator<long long>>::__base_destruct_at_end[abi:ue170006](long long*) in 1931D-f28fab.o
std::__1::allocator<long long>::deallocate[abi:ue170006](long long*, unsigned long) in 1931D-f28fab.o
"___cxa_free_exception", referenced from:
std::__1::__throw_length_error[abi:ue170006](char const*) in 1931D-f28fab.o
"___cxa_throw", referenced from:
std::__1::__throw_length_error[abi:ue170006](char const*) in 1931D-f28fab.o
std::__throw_bad_array_new_length[abi:ue170006]() in 1931D-f28fab.o
"___gxx_personality_v0", referenced from:
/private/var/folders/pt/csddh2cd0fq4krbz3vjkgf7m0000gn/T/1931D-f28fab.o
**ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)**
But Instead when I use this below code it works fins, because I am giving reference link to C++ files, I guess so.
gcc 1931D.cpp -o 1931D -lstdc++
Can you please tell me why it's happening in my PC? Is there any way to avoid this
Also, if you can tell me how can I reset whole C++ or compiler(gcc) in MacBook Air m2 then it will be really helpful?
I tried this gcc 1931D.cpp -o 1931D -lstdc++
and it's working fine but, why I have to write "-lstdc++". And its also create problem in using vsCode and using its cpp extension.