【问题标题】:XMPP client library gloox - linker cannot find symbolXMPP 客户端库 gloox - 链接器找不到符号
【发布时间】:2011-11-06 14:36:30
【问题描述】:

我完全被这个问题难住了,无法真正弄清楚如何解决这个问题。

基本上,我在 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" (?EmptyString@gloox@@3V?$basic_string@DU?$
char_traits@D@std@@V?$allocator@D@2@@std@@B)

当我对我的程序进行详细链接时,我可以看到来自 gloox lib 的所有其他符号都被正确链接:

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)

第二行显示符号已正常导出。

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

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

谢谢!

【问题讨论】:

    标签: visual-studio-2010 linker xmpp symbols gloox


    【解决方案1】:

    旧帖子,但可能对其他人仍有帮助。

    解决方案是确保定义了GLOOX_IMPORTS。它在macros.h 中用于定义:

    define GLOOX_API __declspec( dllexport )
    

    【讨论】:

      【解决方案2】:

      不知道你是否仍然坚持这个问题,但我通过修改 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 = "" );
      

      【讨论】:

      • 抱歉,没看到这个。这看起来像是解决此问题的一种方法。但它仍然没有解释为什么这个问题首先存在。
      【解决方案3】:

      最近我在编译 gloox 相关代码时也遇到了类似的问题。

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

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

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

      包含源文件列表gloox.cpp

      头文件列表包含 gloox.h?

      如果它丢失,请包含它然后我想你会解决这个错误。我用一天的时间发现了这一点,因为我假设我从 gloox 网站下载的库项目应该包含所有必要的源文件,但实际上它不像我假设的那样!

      我是如何检查的?

      我在库项目中改为 build dll 而不是 lib。 如果您在 gloox 库项目中编译 dll 时遇到同样的错误, 那么您应该检查您的库项目是否包含 gloox.cpp。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-04-15
        • 2013-08-27
        • 1970-01-01
        • 2012-02-01
        相关资源
        最近更新 更多