Issue
I have a problem I cannot compile using g++ or gcc. I cannot find the problem in my code after I test it on https://www.onlinegdb.com/ and it seems to output the answer I wanted but when I compile it on my Mingw it trows an error
my MinGW version: 8.1.0
here's my code
#include <iostream>
int main(){
class programmers{
public:
std::string stack = "Unknown";
char rank = 'X';
programmers(std::string x, char y){
stack = x;
rank = y;
}
};
programmers programmer("Fullstack", 'S');
std::cout << "This Programmer's Stack is : " << programmer.stack
<< std::endl << "and have an " << programmer.rank << " Rank";
return 0;
}
here's the compilation log from the stderr using g++ main.cpp test.exe &> outputdebug.txt
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: Dwarf Error: Could not find abbrev number 3926.
test.exe:crtexe.c:(.text+0x4b0): multiple definition of `WinMainCRTStartup'
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.text+0x4b0): first defined here
test.exe:crtexe.c:(.text+0x4e0): multiple definition of `mainCRTStartup'
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.text+0x4e0): first defined here
test.exe:crtexe.c:(.text+0x510): multiple definition of `atexit'
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.text+0x510): first defined here
test.exe:cygming-crtbegin.c:(.text+0x530): multiple definition of `__gcc_register_frame'
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/crtbegin.o:cygming-crtbegin.c:(.text+0x0): first defined here
test.exe:cygming-crtbegin.c:(.text+0x540): multiple definition of `__gcc_deregister_frame'
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/crtbegin.o:cygming-crtbegin.c:(.text+0x10): first defined here
test.exe:main.cpp:(.text+0x550): multiple definition of `main'
C:\Users\lenovo\AppData\Local\Temp\cccop8R3.o:main.cpp:(.text+0xcf): first defined here
test.exe:crtexe.c:(.rdata+0x3c0): multiple definition of `.refptr.__native_startup_state'
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr.__native_startup_state[.refptr.__native_startup_state]+0x0): first defined here
test.exe:crtexe.c:(.rdata+0x490): multiple definition of `.refptr.mingw_initltsdyn_force'
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr.mingw_initltsdyn_force[.refptr.mingw_initltsdyn_force]+0x0): first defined here
test.exe:crtexe.c:(.rdata+0x370): multiple definition of `.refptr.__imp___initenv'
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr.__imp___initenv[.refptr.__imp___initenv]+0x0): first defined here
test.exe:crtexe.c:(.rdata+0x440): multiple definition of `.refptr._matherr'
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr._matherr[.refptr._matherr]+0x0): first defined here
test.exe:crtexe.c:(.rdata+0x4a0): multiple definition of `.refptr.mingw_initltssuo_force'
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr.mingw_initltssuo_force[.refptr.mingw_initltssuo_force]+0x0): first defined here
test.exe:crtexe.c:(.rdata+0x410): multiple definition of `.refptr._dowildcard'
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr._dowildcard[.refptr._dowildcard]+0x0): first defined here
test.exe:crtexe.c:(.rdata+0x470): multiple definition of `.refptr.mingw_initcharmax'
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr.mingw_initcharmax[.refptr.mingw_initcharmax]+0x0): first defined here
test.exe:crtexe.c:(.rdata+0x3a0): multiple definition of `.refptr.__mingw_oldexcpt_handler'
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr.__mingw_oldexcpt_handler[.refptr.__mingw_oldexcpt_handler]+0x0): first defined here
test.exe:crtexe.c:(.rdata+0x3f0): multiple definition of `.refptr.__xi_a'
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr.__xi_a[.refptr.__xi_a]+0x0): first defined here
test.exe:crtexe.c:(.rdata+0x450): multiple definition of `.refptr._newmode'
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr._newmode[.refptr._newmode]+0x0): first defined here
test.exe:crtexe.c:(.CRT+0x8): multiple definition of `mingw_pcppinit'
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.CRT$XCAA+0x0): first defined here
test.exe:crtexe.c:(.rdata+0x480): multiple definition of `.refptr.mingw_initltsdrot_force'
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr.mingw_initltsdrot_force[.refptr.mingw_initltsdrot_force]+0x0): first defined here
test.exe:crtexe.c:(.rdata+0x3b0): multiple definition of `.refptr.__native_startup_lock'
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr.__native_startup_lock[.refptr.__native_startup_lock]+0x0): first defined here
test.exe:crtexe.c:(.rdata+0x350): multiple definition of `.refptr.__dyn_tls_init_callback'
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr.__dyn_tls_init_callback[.refptr.__dyn_tls_init_callback]+0x0): first defined here
test.exe:crtexe.c:(.rdata+0x310): multiple definition of `.refptr._ZSt4cout'
C:\Users\lenovo\AppData\Local\Temp\cccop8R3.o:main.cpp:(.rdata$.refptr._ZSt4cout[.refptr._ZSt4cout]+0x0): first defined here
test.exe:crtexe.c:(.data+0x0): multiple definition of `__mingw_winmain_nShowCmd'
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.data+0x0): first defined here
test.exe:crtexe.c:(.CRT+0x20): multiple definition of `mingw_pcinit'
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.CRT$XIAA+0x0): first defined here
test.exe:crtexe.c:(.rdata+0x430): multiple definition of `.refptr._gnu_exception_handler'
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr._gnu_exception_handler[.refptr._gnu_exception_handler]+0x0): first defined here
test.exe:crtexe.c:(.rdata+0x460): multiple definition of `.refptr.mingw_app_type'
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr.mingw_app_type[.refptr.mingw_app_type]+0x0): first defined here
test.exe:crtexe.c:(.rdata+0x360): multiple definition of `.refptr.__image_base__'
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr.__image_base__[.refptr.__image_base__]+0x0): first defined here
test.exe:crtexe.c:(.rdata+0x420): multiple definition of `.refptr._fmode'
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr._fmode[.refptr._fmode]+0x0): first defined here
test.exe:crtexe.c:(.idata+0x3a8): multiple definition of `__imp__ZSt4cout'
test.exe:crtexe.c:(.idata+0x3a8): first defined here
test.exe:crtexe.c:(.rdata+0x3d0): multiple definition of `.refptr.__xc_a'
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr.__xc_a[.refptr.__xc_a]+0x0): first defined here
test.exe:crtexe.c:(.rdata+0x400): multiple definition of `.refptr.__xi_z'
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr.__xi_z[.refptr.__xi_z]+0x0): first defined here
test.exe:crtexe.c:(.rdata+0x300): multiple definition of `.refptr._MINGW_INSTALL_DEBUG_MATHERR'
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr._MINGW_INSTALL_DEBUG_MATHERR[.refptr._MINGW_INSTALL_DEBUG_MATHERR]+0x0): first defined here
test.exe:crtexe.c:(.rdata+0x3e0): multiple definition of `.refptr.__xc_z'
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr.__xc_z[.refptr.__xc_z]+0x0): first defined here
C:\Users\lenovo\AppData\Local\Temp\cccop8R3.o:main.cpp:(.rdata$.refptr._ZSt4cout[.refptr._ZSt4cout]+0x0): multiple definition of `__fu0__ZSt4cout'
test.exe:crtexe.c:(.rdata+0x310): first defined here
collect2.exe: error: ld returned 1 exit status
here's the compilation log from the stderr using g++ main.cpp test.exe &> outputdebug.txt
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: Dwarf Error: Could not find abbrev number 3926.
test.exe:crtexe.c:(.text+0x4b0): multiple definition of `WinMainCRTStartup'
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.text+0x4b0): first defined here
test.exe:crtexe.c:(.text+0x4e0): multiple definition of `mainCRTStartup'
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.text+0x4e0): first defined here
test.exe:crtexe.c:(.text+0x510): multiple definition of `atexit'
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.text+0x510): first defined here
test.exe:cygming-crtbegin.c:(.text+0x530): multiple definition of `__gcc_register_frame'
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/crtbegin.o:cygming-crtbegin.c:(.text+0x0): first defined here
test.exe:cygming-crtbegin.c:(.text+0x540): multiple definition of `__gcc_deregister_frame'
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/crtbegin.o:cygming-crtbegin.c:(.text+0x10): first defined here
test.exe:main.cpp:(.text+0x550): multiple definition of `main'
C:\Users\lenovo\AppData\Local\Temp\ccGPBLYb.o:main.cpp:(.text+0xcf): first defined here
test.exe:crtexe.c:(.rdata+0x3c0): multiple definition of `.refptr.__native_startup_state'
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr.__native_startup_state[.refptr.__native_startup_state]+0x0): first defined here
test.exe:crtexe.c:(.rdata+0x490): multiple definition of `.refptr.mingw_initltsdyn_force'
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr.mingw_initltsdyn_force[.refptr.mingw_initltsdyn_force]+0x0): first defined here
test.exe:crtexe.c:(.rdata+0x370): multiple definition of `.refptr.__imp___initenv'
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr.__imp___initenv[.refptr.__imp___initenv]+0x0): first defined here
test.exe:crtexe.c:(.rdata+0x440): multiple definition of `.refptr._matherr'
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr._matherr[.refptr._matherr]+0x0): first defined here
test.exe:crtexe.c:(.rdata+0x4a0): multiple definition of `.refptr.mingw_initltssuo_force'
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr.mingw_initltssuo_force[.refptr.mingw_initltssuo_force]+0x0): first defined here
test.exe:crtexe.c:(.rdata+0x410): multiple definition of `.refptr._dowildcard'
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr._dowildcard[.refptr._dowildcard]+0x0): first defined here
test.exe:crtexe.c:(.rdata+0x470): multiple definition of `.refptr.mingw_initcharmax'
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr.mingw_initcharmax[.refptr.mingw_initcharmax]+0x0): first defined here
test.exe:crtexe.c:(.rdata+0x3a0): multiple definition of `.refptr.__mingw_oldexcpt_handler'
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr.__mingw_oldexcpt_handler[.refptr.__mingw_oldexcpt_handler]+0x0): first defined here
test.exe:crtexe.c:(.rdata+0x3f0): multiple definition of `.refptr.__xi_a'
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr.__xi_a[.refptr.__xi_a]+0x0): first defined here
test.exe:crtexe.c:(.rdata+0x450): multiple definition of `.refptr._newmode'
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr._newmode[.refptr._newmode]+0x0): first defined here
test.exe:crtexe.c:(.CRT+0x8): multiple definition of `mingw_pcppinit'
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.CRT$XCAA+0x0): first defined here
test.exe:crtexe.c:(.rdata+0x480): multiple definition of `.refptr.mingw_initltsdrot_force'
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr.mingw_initltsdrot_force[.refptr.mingw_initltsdrot_force]+0x0): first defined here
test.exe:crtexe.c:(.rdata+0x3b0): multiple definition of `.refptr.__native_startup_lock'
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr.__native_startup_lock[.refptr.__native_startup_lock]+0x0): first defined here
test.exe:crtexe.c:(.rdata+0x350): multiple definition of `.refptr.__dyn_tls_init_callback'
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr.__dyn_tls_init_callback[.refptr.__dyn_tls_init_callback]+0x0): first defined here
test.exe:crtexe.c:(.rdata+0x310): multiple definition of `.refptr._ZSt4cout'
C:\Users\lenovo\AppData\Local\Temp\ccGPBLYb.o:main.cpp:(.rdata$.refptr._ZSt4cout[.refptr._ZSt4cout]+0x0): first defined here
test.exe:crtexe.c:(.data+0x0): multiple definition of `__mingw_winmain_nShowCmd'
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.data+0x0): first defined here
test.exe:crtexe.c:(.CRT+0x20): multiple definition of `mingw_pcinit'
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.CRT$XIAA+0x0): first defined here
test.exe:crtexe.c:(.rdata+0x430): multiple definition of `.refptr._gnu_exception_handler'
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr._gnu_exception_handler[.refptr._gnu_exception_handler]+0x0): first defined here
test.exe:crtexe.c:(.rdata+0x460): multiple definition of `.refptr.mingw_app_type'
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr.mingw_app_type[.refptr.mingw_app_type]+0x0): first defined here
test.exe:crtexe.c:(.rdata+0x360): multiple definition of `.refptr.__image_base__'
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr.__image_base__[.refptr.__image_base__]+0x0): first defined here
test.exe:crtexe.c:(.rdata+0x420): multiple definition of `.refptr._fmode'
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr._fmode[.refptr._fmode]+0x0): first defined here
test.exe:crtexe.c:(.idata+0x3a8): multiple definition of `__imp__ZSt4cout'
test.exe:crtexe.c:(.idata+0x3a8): first defined here
test.exe:crtexe.c:(.rdata+0x3d0): multiple definition of `.refptr.__xc_a'
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr.__xc_a[.refptr.__xc_a]+0x0): first defined here
test.exe:crtexe.c:(.rdata+0x400): multiple definition of `.refptr.__xi_z'
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr.__xi_z[.refptr.__xi_z]+0x0): first defined here
test.exe:crtexe.c:(.rdata+0x300): multiple definition of `.refptr._MINGW_INSTALL_DEBUG_MATHERR'
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr._MINGW_INSTALL_DEBUG_MATHERR[.refptr._MINGW_INSTALL_DEBUG_MATHERR]+0x0): first defined here
test.exe:crtexe.c:(.rdata+0x3e0): multiple definition of `.refptr.__xc_z'
C:/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.rdata$.refptr.__xc_z[.refptr.__xc_z]+0x0): first defined here
C:\Users\lenovo\AppData\Local\Temp\ccGPBLYb.o:main.cpp:(.rdata$.refptr._ZSt4cout[.refptr._ZSt4cout]+0x0): multiple definition of `__fu0__ZSt4cout'
test.exe:crtexe.c:(.rdata+0x310): first defined here
C:\Users\lenovo\AppData\Local\Temp\ccGPBLYb.o:main.cpp:(.text+0x28): undefined reference to `std::allocator<char>::allocator()'
C:\Users\lenovo\AppData\Local\Temp\ccGPBLYb.o:main.cpp:(.text+0x3e): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)'
C:\Users\lenovo\AppData\Local\Temp\ccGPBLYb.o:main.cpp:(.text+0x4a): undefined reference to `std::allocator<char>::~allocator()'
C:\Users\lenovo\AppData\Local\Temp\ccGPBLYb.o:main.cpp:(.text+0x62): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator=(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
C:\Users\lenovo\AppData\Local\Temp\ccGPBLYb.o:main.cpp:(.text+0x7e): undefined reference to `std::allocator<char>::~allocator()'
C:\Users\lenovo\AppData\Local\Temp\ccGPBLYb.o:main.cpp:(.text+0x98): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
C:\Users\lenovo\AppData\Local\Temp\ccGPBLYb.o:main.cpp:(.text+0xc4): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
C:\Users\lenovo\AppData\Local\Temp\ccGPBLYb.o:main.cpp:(.text+0xed): undefined reference to `std::allocator<char>::allocator()'
C:\Users\lenovo\AppData\Local\Temp\ccGPBLYb.o:main.cpp:(.text+0x107): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)'
C:\Users\lenovo\AppData\Local\Temp\ccGPBLYb.o:main.cpp:(.text+0x129): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
C:\Users\lenovo\AppData\Local\Temp\ccGPBLYb.o:main.cpp:(.text+0x135): undefined reference to `std::allocator<char>::~allocator()'
C:\Users\lenovo\AppData\Local\Temp\ccGPBLYb.o:main.cpp:(.text+0x157): 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:\Users\lenovo\AppData\Local\Temp\ccGPBLYb.o:main.cpp:(.text+0x166): undefined reference to `std::ostream::operator<<(std::ostream& (*)(std::ostream&))'
C:\Users\lenovo\AppData\Local\Temp\ccGPBLYb.o:main.cpp:(.text+0x186): 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)'
C:\Users\lenovo\AppData\Local\Temp\ccGPBLYb.o:main.cpp:(.text+0x1b9): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
C:\Users\lenovo\AppData\Local\Temp\ccGPBLYb.o:main.cpp:(.text+0x1ca): undefined reference to `std::allocator<char>::~allocator()'
C:\Users\lenovo\AppData\Local\Temp\ccGPBLYb.o:main.cpp:(.xdata+0xc): undefined reference to `__gxx_personality_seh0'
C:\Users\lenovo\AppData\Local\Temp\ccGPBLYb.o:main.cpp:(.xdata+0x40): undefined reference to `__gxx_personality_seh0'
C:\Users\lenovo\AppData\Local\Temp\ccGPBLYb.o:main.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> >&)'
collect2.exe: error: ld returned 1 exit status
Solution
I just tried your code with MinGW-w64 GCC 12.1.0 from https://winlibs.com/ and there was no error building with g++ main.cpp -o test.exe
and the program runs fine.
So it looks like your build environment is somehow broken.
The advantage of using the standalone build from https://winlibs.com/ is that you can just extract it (no installation procedure needed), so you can leave your current build environment untouched.
Answered By - Brecht Sanders Answer Checked By - Cary Denson (WPSolving Admin)