2

I am totally stumped with this issue and cannot really figure how to solve this problem.

Basically, I compiled the gloox library in Visual Studio 2010 (which worked totally fine with a minor tweak) and got a .lib and a .dll file. I am now trying to use this in a different program which uses a lot of gloox functionality. I am able to link most symbols fine, except one:

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)

When I do verbose linking of my program, I can see that all other symbols from gloox lib are being linked to 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)
...

So I thought, may the symbol is not exported right and I did this:

dumpbin.exe /exports gloox 1.0.lib

And among other things I saw this:

??_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)

The second line shows that the symbol has been exported fine.

Now the only difference I can think of is that the symbols being loaded correctly are all functions, and this particular one is a variable. Still, as long as its exported right, the linker should see it, right?

Any help would be greatly appreciated. If you need any more information please let me know.

Thanks!

bcause
  • 1,303
  • 12
  • 29
verma
  • 1,285
  • 1
  • 13
  • 19

3 Answers3

3

Old post, but might still be helpful for others.

The solution is to make sure GLOOX_IMPORTS is defined. It's used in macros.h for defining:

define GLOOX_API __declspec( dllexport )
bcause
  • 1,303
  • 12
  • 29
0

Don't know if you're still stuck on this but I fixed this problem by modifying the message.h file in the gloox includes. I change the constructor from:

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 );

to:

Message( MessageType type, const JID& to,
         const std::string& body = "", const std::string& subject = "",
         const std::string& thread = "", const std::string& xmllang = "" );
sler
  • 974
  • 1
  • 11
  • 19
  • Sorry, didn't see this. This looks like a way to work around this problem. But it still doesn't explain why this issue exists in the first place. – verma Oct 16 '12 at 17:52
0

Recently I also faced similar problem when I tried to compile gloox related code.

I found it is because the library project does not include the source file that is having the definition of the so called unresolved external symbol.

For your case, the unresolved external symbol is gloox::EmptyString It is defined at gloox.cpp.

So check your gloox library project, does its

Sources files list included gloox.cpp?

Header files list included gloox.h?

If it is missing, please include it then I think you will solve that error. I used one day to find this out as I assumed the library project I downloaded from gloox website should include all necessary source file but actually it is not like what I assumed !

How did I check?

I change to build dll instead of lib in the library project. If you have same error while you compiling the dll in the gloox library project, then you should check whether your library project included the gloox.cpp.

V-SHY
  • 3,925
  • 4
  • 31
  • 47