我完全被这个问题所困扰,实在想不出如何解决这个问题。
基本上,我在Visual 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中的所有其他符号都被链接到了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 gloox1.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)第二行显示符号已被很好地导出。
现在我能想到的唯一的区别是,正确加载的符号都是函数,而这个特定的符号是一个变量。不过,只要它出口的权利,链接应该看到它,对吗?
任何帮助都将不胜感激。如果您需要更多的信息,请告诉我。
谢谢!
发布于 2013-07-19 06:44:32
老职位,但仍可能对其他人有所帮助。
解决方案是确保定义了GLOOX_IMPORTS。它在macros.h中用于定义:
define GLOOX_API __declspec( dllexport )发布于 2012-08-21 08:51:33
不知道您是否还停留在这个问题上,但是我通过修改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 = "" );发布于 2014-12-31 03:06:08
最近,当我试图编译gloox相关代码时,也遇到了类似的问题。
我发现这是因为库项目不包括具有所谓未解析外部符号定义的源文件。
对于您的情况,未解决的外部符号是gloox::EmptyString --它是在gloox.cpp中定义的。
所以检查你的gloox库项目,做它的
源文件列表包括gloox.cpp? 头文件列表包括gloox.h?
如果它丢失了,请包括--那么我想你会解决这个错误的。我用一天来找出这一点,因为我认为我从gloox网站下载的库项目应该包括所有必要的源文件,但实际上它不像我所设想的那样!
我是如何检查的
我在库项目中更改为build 而不是lib。如果在gloox库项目中编译dll时具有相同的错误,则应检查库项目是否包含gloox.cpp。
https://stackoverflow.com/questions/8027727
复制相似问题