我完全被这个问题难住了,无法真正弄清楚如何解决这个问题。
基本上,我编译了gloox Visual Studio 2010 中的库(只需稍加调整就可以正常工作)并获得一个 .lib 和一个 .dll 文件。我现在尝试在另一个使用大量 gloox 功能的程序中使用它。我能够很好地链接大多数符号,除了一个:
1>test.obj : error LNK2001: unresolved external symbol "class
std::basic_string<char,struct std::char_traits<char>,
class std::allocator<char> >
const gloox::EmptyString" (?EmptyString@gloox@@3V?$basic_string@DU?$
char_traits@D@std@@V?$allocator@D@2@@std@@B)
当我对程序进行详细链接时,我可以看到 gloox lib 中的所有其他符号都链接到了fine:
1> Searching ..\..\lib\lib\gloox 1.0.lib:
1> Found "public: virtual __thiscall gloox::Message::~Message(void)" (?? 1Message@gloox@@UAE@XZ)
1> Referenced in test.obj
1> Loaded gloox 1.0.lib(gloox 1.0.dll)
1> Found "public: __thiscall gloox::Message::Message(enum gloox::Message::MessageType,class gloox::JID const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (??0Message@gloox@@QAE@W4MessageType@01@ABVJID@1@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@222@Z)
1> Referenced in test.obj
1> Loaded gloox 1.0.lib(gloox 1.0.dll)
1> Found "public: void __thiscall gloox::ClientBase::registerPresenceHandler(class gloox::PresenceHandler *)" (?registerPresenceHandler@ClientBase@gloox@@QAEXPAVPresenceHandler@2@@Z)
1> Referenced in test.obj
1> Loaded gloox 1.0.lib(gloox 1.0.dll)
...
所以我想,可能符号没有正确导出,我这样做了:
dumpbin.exe /exports gloox 1.0.lib
除其他外,我还看到了以下内容:
??_FXHtmlIM@gloox@@QAEXXZ (public: void __thiscall gloox::XHtmlIM::`default constructor closure'(void))
?EmptyString@gloox@@3V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@B (class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const gloox::EmptyString)
?GLOOX_CAPS_NODE@gloox@@3V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@B (class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const gloox::GLOOX_CAPS_NODE)
第二行显示符号已正常导出。
现在我能想到的唯一区别是正确加载的符号都是函数,而这个特定的函数是一个变量。不过,只要它导出正确,链接器就应该看到它,对吗?
任何帮助将不胜感激。如果您需要更多信息,请告诉我。
谢谢!
最佳答案
旧帖子,但可能对其他人仍然有帮助。
解决方案是确保定义了 GLOOX_IMPORTS
。它在 macros.h
中用于定义:
define GLOOX_API __declspec( dllexport )
关于visual-studio-2010 - XMPP 客户端库 gloox - 链接器找不到符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8027727/