2011-11-06 109 views
2

我完全不知道如何解决此问题。XMPP客户端库gloox - 链接器找不到符号

基本上,我在Visual Studio 2010中编译了gloox库(它在一个小的调整中工作得很好),并且得到了一个.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" ([email protected]@@[email protected]?$ 
[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@B) 

当我做我的程序的详细链接,我可以看到,从gloox lib中所有其他符号如链接到罚款:

1>  Searching ..\..\lib\lib\gloox 1.0.lib: 
1>  Found "public: virtual __thiscall gloox::Message::~Message(void)" (??  [email protected]@@[email protected]) 
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 &)" ([email protected]@@[email protected]@[email protected]@[email protected][email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]) 
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 *)" ([email protected]@[email protected]@[email protected]@@Z) 
1>   Referenced in test.obj 
1>   Loaded gloox 1.0.lib(gloox 1.0.dll) 
... 

因此,我认为,可以将符号不正确的出口,我这样做:

DUMPBIN.EXE /出口gloox 1.0.lib

而且除其他事项外,我看到这样的:

??_FXHtm[email protected]@@QAEXXZ (public: void __thiscall gloox::XHtmlIM::`default constructor closure'(void)) 
[email protected]@@[email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@B (class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const gloox::EmptyString) 
[email protected]@@[email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@B (class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const gloox::GLOOX_CAPS_NODE) 

第二行显示的符号已经导出的罚款。

现在我能想到的唯一区别是正确加载的符号都是函数,而这个特定的符号是一个变量。不过,只要它的出口权,链接器应该看到它,对吧?

任何帮助将不胜感激。如果您需要更多信息,请告诉我。

谢谢!

回答

0

不知道你是否仍然坚持这个,但我通过修改gloox包括的message.h文件来解决这个问题。我改变构造从:

Message(MessageType type, const JID& to, 
     const std::string& body = EmptyString, const std::string& subject = EmptyString, 
     const std::string& thread = EmptyString, const std::string& xmllang = EmptyString); 

到:

Message(MessageType type, const JID& to, 
     const std::string& body = "", const std::string& subject = "", 
     const std::string& thread = "", const std::string& xmllang = ""); 
+0

对不起,没有看到这个。这看起来像解决此问题的一种方法。但它仍然无法解释为什么这个问题首先存在。 – verma

3

旧的职位,但仍可能对他人有所帮助。

解决方法是确保GLOOX_IMPORTS已定义。它在macros.h用于定义:

define GLOOX_API __declspec(dllexport) 
0

最近我也遇到了类似的问题,当我试图编译gloox相关的代码。

我发现这是因为库项目没有包含具有所谓的未解析外部符号定义的源文件。

对于您的情况,无法解析的外部符号是gloox :: EmptyString 它在gloox.cpp中定义。

所以检查gloox库项目,做它的

源文件列表包含gloox.cpp

包含头文件列表gloox.h?

如果缺少,请包括然后我想你会解决这个错误。我用了一天的时间来发现这一点,因为我认为我从gloox网站下载的图书馆项目应该包括所有必要的源文件,但实际上并不像我所设想的那样!

我是如何检查

我更改为构建dll而不是库项目中的lib。 如果你有相同的错误当你在gloox库项目中编译dll时,你应该检查你的库项目是否包含gloox.cpp。