A problem caused by mismatch between the MinGW version and the library version, leading to undefined reference to __gxx_personality_v0

⌚Time: 2026-09-13 18:39:05

👨‍💻Author: Jack Ge

I compiled a program that uses the QR code library ZXing. When I compiled it, I got an error at the linking stage at the end:

D:\BuildTools\zxing-cpp-1.0.6\lib/libZXingCore.a(QRAlignmentPatternFinder.cpp.obj):QRAlignmentPatternFinder.cpp:(.eh_frame+0x13): undefined reference to `__gxx_personality_v0'
D:\BuildTools\zxing-cpp-1.0.6\lib/libZXingCore.a(QRBitMatrixParser.cpp.obj):QRBitMatrixParser.cpp:(.text+0xf11): undefined reference to `_Unwind_Resume'
D:\BuildTools\zxing-cpp-1.0.6\lib/libZXingCore.a(QRBitMatrixParser.cpp.obj):QRBitMatrixParser.cpp:(.eh_frame+0xf3): undefined reference to `__gxx_personality_v0'
D:\BuildTools\zxing-cpp-1.0.6\lib/libZXingCore.a(QRDataBlock.cpp.obj):QRDataBlock.cpp:(.text+0x4c0): undefined reference to `_Unwind_Resume'
D:\BuildTools\zxing-cpp-1.0.6\lib/libZXingCore.a(QRDataBlock.cpp.obj):QRDataBlock.cpp:(.eh_frame+0x13): undefined reference to `__gxx_personality_v0'
D:\BuildTools\zxing-cpp-1.0.6\lib/libZXingCore.a(QRDataMask.cpp.obj):QRDataMask.cpp:(.text+0x1c0): undefined reference to `_Unwind_Resume'
D:\BuildTools\zxing-cpp-1.0.6\lib/libZXingCore.a(QRDataMask.cpp.obj):QRDataMask.cpp:(.eh_frame+0xe3): undefined reference to `__gxx_personality_v0'
D:\BuildTools\zxing-cpp-1.0.6\lib/libZXingCore.a(GenericGFPoly.cpp.obj):GenericGFPoly.cpp:(.text+0x1444): undefined reference to `_Unwind_Resume'
D:\BuildTools\zxing-cpp-1.0.6\lib/libZXingCore.a(GenericGFPoly.cpp.obj):GenericGFPoly.cpp:(.text+0x14d2): undefined reference to `_Unwind_Resume'
D:\BuildTools\zxing-cpp-1.0.6\lib/libZXingCore.a(GenericGFPoly.cpp.obj):GenericGFPoly.cpp:(.eh_frame+0x28f): undefined reference to `__gxx_personality_v0'

I checked that this library has the correct links. I also ran make clean to clear out the old object files. But the problem still exists. The likely issue now is that the version of MinGW I'm using doesn't match the version ZXing was compiled with. I asked AI, and it replied:

MinGW has different versions, and their exception handling methods are not compatible: SJLJ (older, slower) and DWARF2 (modern, used by most of the latest MinGW-w64 by default). If you compile libZXingCore.a with one version but link it using another, you'll get these undefined references. A common reason is using a ZXing library that was precompiled for one MinGW version, while your compiler is using a different version.

The GCC compiler in MinGW has three C exception handling models, and they rely on completely different runtime library symbols:

exception model Key symbol The corresponding runtime DLL
DWARF2 __gxx_personality_v0、_Unwind_Resume libgcc_s_dw2-1.dll
SJLJ __gxx_personality_sj0、__Unwind_SjLj_Resume libgcc_s_sjlj-1.dll
SEH(64 Bit) __gxx_personality_seh0、_Unwind_Resume libgcc_s_seh-1.dll

The error clearly points to __gxx_personality_v0 and _Unwind_Resume, which are characteristics of the DWARF2 model. I noticed that my system PATH environment variable has two versions of Mingw:

i686-8.1.0-release-posix-sjlj-rt_v6-rev0
i686-7.3.0-release-posix-dwarf-rt_v5-rev0

The default is i686-8.1.0-release-posix-sjlj-rt_v6-rev0. I moved i686-7.3.0-release-posix-dwarf-rt_v5-rev0 to the front to use the dwarf version of mingw, and then it compiled successfully.