今天遇到一个C++编译问题。

我用Gloox编译成dll,然后再自己写个C++ console,2个项目在一个解决方案中(这使我一顿被蒙蔽),去调用它,build error如下:

error LNK2001: unresolved external symbol "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const gloox::GLOOX_VERSION" (?GLOOX_VERSION@gloox@@3V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@B

解决方法:

参考http://camaya.net/glooxlist/dev/msg00125.html,

关键在GLOOX_API这个宏的解释上,

在C++ console的Project configuration properties\ c/c++ \Preprocesser\Preprcessor Definitions中加入GLOOX_IMPORTS 或 DLL_IMPORT 使extern 变量声明为 __declspec( dllimport );这样exe程序才认为这是个要从外部导入的变量。

否则不会去外部(dll)中找,自然就说无法解析即找不到了。

 

帮助别人就是提高自己