ARTICLE AD BOX
I was trying to learn C++ programming using VS Code, but I ran into the following problem. When I launched the program from the official VS Code website, I got the error shown in the screenshot. Exit code: -1. What does it mean? How can I fix it? There aren't any errors in the code itself, but something's wrong with the compiler. I was confused by the errors shown in the other screenshot that appeared in the terminal during the installation of the MinGW-w64 toolchain. I searched online for information about this, but I couldn't seem to find the solution I needed. So, how do I fix all this?
Link to the tutorial I followed: https://code.visualstudio.com/docs/cpp/config-mingw
Errors and warnings during the installation of the MinGW-w64 toolchain:
error: failed retrieving file 'mingw-w64-ucrt-x86_64-openssl-3.6.0-1-any.pkg.tar.zst' from mirror.msys2.org : Connection timed out after 10017 milliseconds error: failed retrieving file 'mingw-w64-ucrt-x86_64-ncurses-6.5.20250927-2-any.pkg.tar.zst' from mirror.msys2.org : Operation too slow. Less than 1 bytes/sec transferred the last 10 seconds error: failed retrieving file 'texinfo-7.2-2-x86_64.pkg.tar.zst' from mirror.msys2.org : Operation too slow. Less than 1 bytes/sec transferred the last 10 seconds warning: too many errors from mirror.msys2.org, skipping for the remainder of this transaction error: failed retrieving file 'mingw-w64-ucrt-x86_64-isl-0.27-1-any.pkg.tar.zst' from mirror.msys2.org : Operation too slow. Less than 1 bytes/sec transferred the last 10 seconds error: failed retrieving file 'mingw-w64-ucrt-x86_64-gcc-libs-15.2.0-8-any.pkg.tar.zst' from mirror.msys2.org : Operation too slow. Less than 1 bytes/sec transferred the last 10 seconds error: failed retrieving file 'mingw-w64-ucrt-x86_64-openssl-3.6.0-1-any.pkg.tar.zst' from repo.msys2.org : Operation too slow. Less than 1 bytes/sec transferred the last 10 seconds error: failed retrieving file 'mingw-w64-ucrt-x86_64-ncurses-6.5.20250927-2-any.pkg.tar.zst' from repo.msys2.org : Operation too slow. Less than 1 bytes/sec transferred the last 10 seconds error: failed retrieving file 'texinfo-7.2-2-x86_64.pkg.tar.zst' from repo.msys2.org : Operation too slow. Less than 1 bytes/sec transferred the last 10 seconds warning: too many errors from repo.msys2.org, skipping for the remainder of this transaction error: failed retrieving file 'mingw-w64-ucrt-x86_64-isl-0.27-1-any.pkg.tar.zst' from repo.msys2.org : Operation too slow. Less than 1 bytes/sec transferred the last 10 seconds error: failed retrieving file 'mingw-w64-ucrt-x86_64-gcc-libs-15.2.0-8-any.pkg.tar.zst' from repo.msys2.org : Operation too slow. Less than 1 bytes/sec transferred the last 10 secondsThe code (Exit code: -1):
#include <iostream> #include <vector> #include <string> using namespace std; int main() { vector<string> msg {"Hello", "C++", "World", "from", "VS Code", "and the C++ extension!"}; for (const string& word : msg) { cout << word << " "; } cout << endl; }Compilation commands:
* Executing task: C/C++: gcc.exe build active file Starting build... cmd /c chcp 65001>nul && C:/msys64/ucrt64/bin/gcc.exe -fdiagnostics-color=always -g C:\Users\Егор\projects\helloworld\hell.cpp -o C:\Users\Егор\projects\helloworld\hell.exe C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/15.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\A946~1\AppData\Local\Temp\ccN4gmbj.o: in function `main': C:/Users/Егор/projects/helloworld/hell.cpp:13:(.text+0x142): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <char, std::char_traits<char>, std::allocator<char> >(std::basic_ostream<char, std::char_traits<char> >&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)' C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/15.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/Егор/projects/helloworld/hell.cpp:13:(.text+0x154): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)' C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/15.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/Егор/projects/helloworld/hell.cpp:15:(.text+0x1ab): undefined reference to `std::ostream::operator<<(std::ostream& (*)(std::ostream&))' C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/15.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\A946~1\AppData\Local\Temp\ccN4gmbj.o:hell.cpp:(.xdata+0x18): undefined reference to `__gxx_personality_seh0' C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/15.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\A946~1\AppData\Local\Temp\ccN4gmbj.o:hell.cpp:(.xdata$_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED1Ev+0xc): undefined reference to `__gxx_personality_seh0' C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/15.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\A946~1\AppData\Local\Temp\ccN4gmbj.o: in function `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string<std::allocator<char> >(char const*, std::allocator<char> const&)': C:/msys64/ucrt64/include/c++/15.2.0/bits/basic_string.h:711:(.text$_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC1IS3_EEPKcRKS3_[_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC1IS3_EEPKcRKS3_]+0x4c): undefined reference to `std::__throw_logic_error(char const*)' C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/15.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\A946~1\AppData\Local\Temp\ccN4gmbj.o:hell.cpp:(.xdata$_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC1IS3_EEPKcRKS3_+0x10): undefined reference to `__gxx_personality_seh0' C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/15.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\A946~1\AppData\Local\Temp\ccN4gmbj.o:hell.cpp:(.xdata$_ZNSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS5_EEC1ESt16initializer_listIS5_ERKS6_+0x10): undefined reference to `__gxx_personality_seh0' C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/15.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\A946~1\AppData\Local\Temp\ccN4gmbj.o:hell.cpp:(.xdata$_ZNSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS5_EED1Ev+0xc): undefined reference to `__gxx_personality_seh0' C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/15.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\A946~1\AppData\Local\Temp\ccN4gmbj.o:hell.cpp:(.xdata$_ZZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPKcEEvT_S8_St20forward_iterator_tagEN6_GuardD1Ev+0xc): undefined reference to `__gxx_personality_seh0' C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/15.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\A946~1\AppData\Local\Temp\ccN4gmbj.o:hell.cpp:(.xdata$_ZNSt12_Vector_baseINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS5_EED2Ev+0xc): undefined reference to `__gxx_personality_seh0' C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/15.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\A946~1\AppData\Local\Temp\ccN4gmbj.o: in function `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_create(unsigned long long&, unsigned long long)': C:/msys64/ucrt64/include/c++/15.2.0/bits/basic_string.tcc:149:(.text$_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE9_M_createERyy[_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE9_M_createERyy]+0x3f): undefined reference to `std::__throw_length_error(char const*)' C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/15.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\A946~1\AppData\Local\Temp\ccN4gmbj.o: in function `std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >::_S_check_init_len(unsigned long long, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > const&)': C:/msys64/ucrt64/include/c++/15.2.0/bits/stl_vector.h:2211:(.text$_ZNSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS5_EE17_S_check_init_lenEyRKS6_[_ZNSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS5_EE17_S_check_init_lenEyRKS6_]+0x5c): undefined reference to `std::__throw_length_error(char const*)' C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/15.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\A946~1\AppData\Local\Temp\ccN4gmbj.o: in function `std::__new_allocator<char>::deallocate(char*, unsigned long long)': C:/msys64/ucrt64/include/c++/15.2.0/bits/new_allocator.h:172:(.text$_ZNSt15__new_allocatorIcE10deallocateEPcy[_ZNSt15__new_allocatorIcE10deallocateEPcy]+0x20): undefined reference to `operator delete(void*, unsigned long long)' C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/15.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\A946~1\AppData\Local\Temp\ccN4gmbj.o: in function `std::__new_allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::deallocate(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*, unsigned long long)': C:/msys64/ucrt64/include/c++/15.2.0/bits/new_allocator.h:172:(.text$_ZNSt15__new_allocatorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEE10deallocateEPS5_y[_ZNSt15__new_allocatorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEE10deallocateEPS5_y]+0x27): undefined reference to `operator delete(void*, unsigned long long)' C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/15.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\A946~1\AppData\Local\Temp\ccN4gmbj.o: in function `std::__new_allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::allocate(unsigned long long, void const*)': C:/msys64/ucrt64/include/c++/15.2.0/bits/new_allocator.h:139:(.text$_ZNSt15__new_allocatorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEE8allocateEyPKv[_ZNSt15__new_allocatorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEE8allocateEyPKv]+0x4a): undefined reference to `std::__throw_bad_array_new_length()' C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/15.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/msys64/ucrt64/include/c++/15.2.0/bits/new_allocator.h:140:(.text$_ZNSt15__new_allocatorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEE8allocateEyPKv[_ZNSt15__new_allocatorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEE8allocateEyPKv]+0x4f): undefined reference to `std::__throw_bad_alloc()' C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/15.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/msys64/ucrt64/include/c++/15.2.0/bits/new_allocator.h:151:(.text$_ZNSt15__new_allocatorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEE8allocateEyPKv[_ZNSt15__new_allocatorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEE8allocateEyPKv]+0x5f): undefined reference to `operator new(unsigned long long)' C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/15.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\A946~1\AppData\Local\Temp\ccN4gmbj.o:hell.cpp:(.xdata$_ZSt16__do_uninit_copyIPKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES7_PS5_ET1_T_T0_S9_+0xc): undefined reference to `__gxx_personality_seh0' C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/15.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\A946~1\AppData\Local\Temp\ccN4gmbj.o: in function `std::__new_allocator<char>::allocate(unsigned long long, void const*)': C:/msys64/ucrt64/include/c++/15.2.0/bits/new_allocator.h:140:(.text$_ZNSt15__new_allocatorIcE8allocateEyPKv[_ZNSt15__new_allocatorIcE8allocateEyPKv]+0x3a): undefined reference to `std::__throw_bad_alloc()' C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/15.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/msys64/ucrt64/include/c++/15.2.0/bits/new_allocator.h:151:(.text$_ZNSt15__new_allocatorIcE8allocateEyPKv[_ZNSt15__new_allocatorIcE8allocateEyPKv]+0x46): undefined reference to `operator new(unsigned long long)' C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/15.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\A946~1\AppData\Local\Temp\ccN4gmbj.o:hell.cpp:(.xdata$_ZSt10_ConstructINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEJRKS5_EEvPT_DpOT0_+0x14): undefined reference to `__gxx_personality_seh0' C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/15.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\A946~1\AppData\Local\Temp\ccN4gmbj.o:hell.cpp:(.xdata$_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC1ERKS4_+0xc): undefined reference to `__gxx_personality_seh0' C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/15.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\A946~1\AppData\Local\Temp\ccN4gmbj.o:hell.cpp:(.rdata$.refptr._ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_[.refptr._ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_]+0x0): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)' C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/15.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\A946~1\AppData\Local\Temp\ccN4gmbj.o:hell.cpp:(.rdata$.refptr._ZSt4cout[.refptr._ZSt4cout]+0x0): undefined reference to `std::cout' collect2.exe: error: ld returned 1 exit status Build finished with error(s). * The terminal process terminated with exit code: -1. * Terminal will be reused by tasks, press any key to close it.