Linking Boost library from Qt application with MinGW

While integrating NetCom’s app_gui module (Qt app) with GLog module that relies on Boost library, I encountered a long long list of linking errors:

g++ -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -mthreads -Wl -Wl,-subsystem,windows -o .\NetCom.exe .\main.o .\MainWindow.o.\TestCaseDialog.o .\RunTestPlanDialog.o .\MsgCommDialog.o .\moc_MainWindow.o .\moc_TestCaseDialog.o .\moc_RunTestPlanDialog.o .\moc_MsgCommDialog.o -L"C:\Qt\2010.02.1\qt\lib" -L"C:\boost_1_41_0\stage\lib" -lmingw32 -lqtmaind -lQtGuid4 -lQtCored4 -llibboost_date_time-mt-d
C:\boost_1_41_0\stage\lib/libboost_date_time-mt-d.lib(greg_month.o): In function `ZN5boost9gregorian10greg_month17get_month_map_ptrEv':
c:/boost_1_41_0/libs/date_time/src/gregorian/greg_month.cpp:36: undefined reference to `__gxx_personality_sj0'
c:/boost_1_41_0/libs/date_time/src/gregorian/greg_month.cpp:36: undefined reference to `_Unwind_SjLj_Register'
c:/boost_1_41_0/libs/date_time/src/gregorian/greg_month.cpp:37: undefined reference to `_Unwind_SjLj_Resume'
c:/boost_1_41_0/libs/date_time/src/gregorian/greg_month.cpp:51: undefined reference to `_Unwind_SjLj_Unregister'
...
...

It occurred on Windows but working fine under Linux. I had been stuck in this linking problem for the past few weeks (not in full time of course), and eventually I figured out the root cause last night. I built Boost from source using MinGW with GCC library 3, while the Qt’s library for the same toolchain is of version 4. To solve the problem, I only need to rebuild Boost library with GCC version 4. And that’s it!

Comments are closed.