尝试将 Qt 应用程序与我的静态库链接时未定义的引用

发布于 2024-08-20 05:46:02 字数 2522 浏览 2 评论 0原文

我有一个用 MinGW 构建的静态库,我试图从 Qt 应用程序链接到该库。我不断收到由库中的目标文件之一引起的链接器错误。该文件实际上声明了几个 Boost 标头,一个用于使用 shared_ptr,另一个用于使我可以使类不可复制。我相信使用此增强功能是导致问题的原因,但我不知道为什么。如果我注释掉 Qt 应用程序中使用文件中定义的类的类,则 Qt 应用程序链接正常。这是输出的错误部分:

C:\blah\build\windows\mingw\libfoo.a(foo_ctis.cpp.obj):foo_ctis.cpp:(.text+0x10a): 未定义的引用 `__gxx_personality_sj0'

C:\blah\build\windows\mingw\libfoo.a(foo_ctis.cpp.obj):foo_ctis.cpp:(.text+0x12f): 未定义的引用 `_Unwind_SjLj_Register'

C:\blah\build\windows\mingw\libfoo.a(foo_ctis.cpp.obj):foo_ctis.cpp:(.text+0x203): 未定义的引用 `_Unwind_SjLj_Resume'

C:\blah\build\windows\mingw\libfoo.a(foo_ctis.cpp.obj):foo_ctis.cpp:(.text+0x20e): 未定义的引用 `_Unwind_SjLj_Unregister'

C:\blah\build\windows\mingw\libfoo.a(foo_ctis.cpp.obj):foo_ctis.cpp:(.text+0x226): 未定义的引用 `__gxx_personality_sj0'

C:\blah\build\windows\mingw\libfoo.a(foo_ctis.cpp.obj):foo_ctis.cpp:(.text+0x24b): 未定义的引用 `_Unwind_SjLj_Register'

C:\blah\build\windows\mingw\libfoo.a(foo_ctis.cpp.obj):foo_ctis.cpp:(.text+0x31f): 未定义的引用 `_Unwind_SjLj_Resume'

C:\blah\build\windows\mingw\libfoo.a(foo_ctis.cpp.obj):foo_ctis.cpp:(.text+0x32a): 未定义的引用 `_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): 未定义的引用 `__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): 未定义的引用 `_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): 未定义的引用 `_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): 未定义的引用 `_Unwind_SjLj_Unregister'collect2:ld 返回 1 退出状态

另一件需要提到的是,我在此类中使用了指向实现的指针。 任何帮助将不胜感激。

已解决: 我发现我的路径中有一个旧版本的 GCC,它是在我的 MinGW 提供的 GCC 版本之前包含的。旧版本包含在我不久前拥有的 GNUStep 包中。我认为这些不同版本的配置导致了问题。感谢 kemiisto,他在解决问题方面走上了正确的道路。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

牵你手 2024-08-27 05:46:02

看来您的静态库已链接到一个 MinGW 发行版(即第 3 版),但您尝试使用其他 MinGW 发行版(即与二进制 Qt 一起发行的第 4 版)将您的应用程序与该库链接。您应该使用与应用程序开发相同的 MinGW 来重建您的库。

更新

可能这是另一个众所周知的问题。查看此主题。 可能还有 2 个不同的文件夹,其中包含 Qt 库

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

您的路径中 。第一个文件夹 (...\bin) 中的库是使用 VS2008 编译的,第二个文件夹 (...\qt\bin) 中的库是使用 MinGW 编译的。应用程序启动时会查找路径变量中的项目。突然,路径变量中包含“错误”库的文件夹出现在包含正确项目的文件夹之前。您可以做的是复制 QtCore4.dll、QtGui4.dll 和其他需要与应用程序可执行文件放在文件夹中的库。希望这有帮助。

关于此问题的一些链接:

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:

流殇 2024-08-27 05:46:02

以防万一其他人遇到此问题:我的项目重建使用了先前构建中的 .o 文件。我在这之间改变了编译器。

事实证明,当我重建同一个项目时,新编译器没有构建新的 .o 文件,因此它们丢失了一些关键信息。删除旧文件并重建后,错误已修复。

我认为从头开始重建,不删除,会起到同样的作用。

Just in case anyone else has this problem: my project rebuild was using .o files from a previous build. I changed compilers in between.

Turns out that when I rebuilt the same project, the new compiler didn't build new .o files, so they were missing some key info. After deleting the old files and rebuilding, the error was fixed.

I assume rebuilding from scratch, without the delete, would work the same.

猫弦 2024-08-27 05:46:02

您可能使用了 gcc 而不是 g++。 gcc 是一个 C 编译器。但 g++ 是一个 c++ 编译器。

如果您有 .cpp 文件,请确保使用 g++。

you may have used gcc instead of g++. gcc is a C compiler. but g++ is a c++ compiler.

just make sure to use g++ if you have .cpp files.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文