Undefined references when trying to link Qt app with my static library

clintsmith picture clintsmith · Feb 3, 2010 · Viewed 9.4k times · Source

I have a static library that I have built with MinGW, I am trying to link to that library from a Qt application. I keep getting linker errors caused by one of the object files in the library. This file actually declares a couple of Boost headers, one for use of shared_ptr and the other so I can make a class noncopyable. I believe using this boost functionality is what is causing the issue but I have no idea why. If I comment out the classes in the Qt app that use the class defined in the file, the Qt app links fine. This is the error part of the output:

C:\blah\build\windows\mingw\libfoo.a(foo_ctis.cpp.obj):foo_ctis.cpp:(.text+0x10a): undefined reference to `__gxx_personality_sj0'

C:\blah\build\windows\mingw\libfoo.a(foo_ctis.cpp.obj):foo_ctis.cpp:(.text+0x12f): undefined reference to `_Unwind_SjLj_Register'

C:\blah\build\windows\mingw\libfoo.a(foo_ctis.cpp.obj):foo_ctis.cpp:(.text+0x203): undefined reference to `_Unwind_SjLj_Resume'

C:\blah\build\windows\mingw\libfoo.a(foo_ctis.cpp.obj):foo_ctis.cpp:(.text+0x20e): undefined reference to `_Unwind_SjLj_Unregister'

C:\blah\build\windows\mingw\libfoo.a(foo_ctis.cpp.obj):foo_ctis.cpp:(.text+0x226): undefined reference to `__gxx_personality_sj0'

C:\blah\build\windows\mingw\libfoo.a(foo_ctis.cpp.obj):foo_ctis.cpp:(.text+0x24b): undefined reference to `_Unwind_SjLj_Register'

C:\blah\build\windows\mingw\libfoo.a(foo_ctis.cpp.obj):foo_ctis.cpp:(.text+0x31f): undefined reference to `_Unwind_SjLj_Resume'

C:\blah\build\windows\mingw\libfoo.a(foo_ctis.cpp.obj):foo_ctis.cpp:(.text+0x32a): undefined reference to `_Unwind_SjLj_Unregister'

C:\blah\build\windows\mingw\libfoo.a(foo_ctis.cpp.obj):foo_ctis.cpp:(.text$_ZN5boost6detail12shared_countC1IN3foo25foo_SomeClassImplEEEPT_[boost::detail::shared_count::shared_count(foo::foo_SomeClassImpl*)]+0xc): undefined reference to `__gxx_personality_sj0'

C:\blah\build\windows\mingw\libfoo.a(foo_ctis.cpp.obj):foo_ctis.cpp:(.text$_ZN5boost6detail12shared_countC1IN3foo25foo_SomeClassImplEEEPT_[boost::detail::shared_count::shared_count(foo::foo_SomeClassImpl*)]+0x31): undefined reference to `_Unwind_SjLj_Register'

C:\blah\build\windows\mingw\libfoo.a(foo_ctis.cpp.obj):foo_ctis.cpp:(.text$_ZN5boost6detail12shared_countC1IN3foo25foo_SomeClassImplEEEPT_[boost::detail::shared_count::shared_count(foo::foo_SomeClassImpl*)]+0xfb): undefined reference to `_Unwind_SjLj_Resume'

C:\blah\build\windows\mingw\libfoo.a(foo_ctis.cpp.obj):foo_ctis.cpp:(.text$_ZN5boost6detail12shared_countC1IN3foo25foo_SomeClassImplEEEPT_[boost::detail::shared_count::shared_count(foo::foo_SomeClassImpl*)]+0x106): undefined reference to `_Unwind_SjLj_Unregister' collect2: ld returned 1 exit status

One other thing to mention is that I am using a pointer to implementation in this class. Any help would be much appreciated.

Solved: I figured out that I had an older version of GCC in my path that was beng included before my MinGW supplied GCC version. The old version was included in a GNUStep package that I had from awhile back. I think that configuration of these different versions was causing problems. Thanks to kemiisto, who was on the right track in solving the issue.

Answer

Wildcat picture Wildcat · Feb 3, 2010

It seems that your static library was linked against one MinGW distribution (i.e. 3rd version) but you try to link your application with this library using other MinGW distribution (i.e. 4th version which is distributed with binary Qt). You should rebuild your library using the same MinGW which you use for your application development.

Update

May be it's another well known problem. Take a look at this topic. You probably have 2 different folders with Qt libs

C:\Qt\2009.05\bin;C:\Qt\2009.05\qt\bin 

in your path too. Libraries in the first folder (...\bin) compiled with VS2008 and libraries in the second one (...\qt\bin) compiled with MinGW. The items in path variable are looked up when your application starts. Suddenly the folder with "wrong" libraries exists before the folder with correct item in your path variable. What you can do is to copy QtCore4.dll, QtGui4.dll and other libraries that you need to folder with your application executable. Hope this helps.

Some links about this problem: