I use mingw-w64 to deploy C++ on windows, everything is normal except when I use the library function, the following problems will be reported at runtime
d:/mingw-w64/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: d:/mingw-w64/bin/../lib/gcc/mingw32/9.2.0/../../../libmingw32.a(mbrscan.o):(.text+0xb6): undefined reference to `SetLastError@4'd:/mingw-w64/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: d:/mingw-w64/bin/../lib/gcc/mingw32/9.2.0/../../../libmingw32.a(wcharmap.o):(.text+0x208): undefined reference to `WideCharToMultiByte@32'd:/mingw-w64/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: d:/mingw-w64/bin/../lib/gcc/mingw32/9.2.0/../../../libmingwex.a(codeset.o):(.text+0xbe): undefined reference to `GetCPInfo@8'd:/mingw-w64/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: d:/mingw-w64/bin/../lib/gcc/mingw32/9.2.0/../../../libmingwex.a(codeset.o):(.text+0x143): undefined reference to `GetCPInfo@8'd:/mingw-w64/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: d:/mingw-w64/bin/../lib/gcc/mingw32/9.2.0/libgcc_eh.a(emutls.o): in function `_gthread_key_create':/home/keith/builds/mingw/gcc-9.2.0-mingw32-cross-native/mingw32/libgcc/./gthr-default.h:590: undefined reference to `TlsAlloc@0'd:/mingw-w64/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: /home/keith/builds/mingw/gcc-9.2.0-mingw32-cross-native/mingw32/libgcc/./gthr-default.h:597: undefined reference to `__mingwthr_key_dtor'd:/mingw-w64/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: d:/mingw-w64/bin/../lib/gcc/mingw32/9.2.0/libgcc_eh.a(emutls.o): in function `_gthread_getspecific':/home/keith/builds/mingw/gcc-9.2.0-mingw32-cross-native/mingw32/libgcc/./gthr-default.h:621: undefined reference to `SetLastError@4'd:/mingw-w64/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: d:/mingw-w64/bin/../lib/gcc/mingw32/9.2.0/libgcc_eh.a(emutls.o): in function `_gthread_setspecific':/home/keith/builds/mingw/gcc-9.2.0-mingw32-cross-native/mingw32/libgcc/./gthr-default.h:629: undefined reference to `TlsSetValue@8'collect2.exe: error: ld returned 1 exit status
What caused this?Can u help me solve it?
--
A minimal example that reproduces what I believe is the problem:
#include <iostream>#include <string>using namespace std;int main(int argc, char* argv[]){ cout << to_string(42) << endl; return 0;}
Link with MinGW GCC 9.2.0
C:\Users\dash\repos\link-error>g++ --versiong++ (MinGW.org GCC Build-20200227-1) 9.2.0Copyright (C) 2019 Free Software Foundation, Inc.This is free software; see the source for copying conditions. There is NOwarranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.C:\Users\dash\repos\link-error>g++ main.cpp -o mainc:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../libmingw32.a(mbrscan.o):(.text+0xb6): undefined reference to `SetLastError@4'c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../libmingw32.a(wcharmap.o):(.text+0x208): undefined reference to `WideCharToMultiByte@32'c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../libmingwex.a(codeset.o):(.text+0xbe): undefined reference to `GetCPInfo@8'c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../libmingwex.a(codeset.o):(.text+0x143): undefined reference to `GetCPInfo@8'collect2.exe: error: ld returned 1 exit status