2

我正在编写一个使用 PugiXml 进行 xml 解析的静态库。这是 Visual Studio 2010 的链接器输出(为了便于阅读,我已将符号替换为省略号):

error LNK2019: unresolved external symbol "public: __thiscall Dae_Library<class Dae_Geometry>::Dae_Library<class Dae_Geometry>(void)" (...) referenced in function "private: bool __thiscall Dae_Doc::ParseDae(void)" (...)
error LNK2019: ^ "public: wchar_t const * __thiscall pugi::xml_node::name(void)const " (...) referenced in function "private: bool __thiscall Dae_Doc::ParseDae(void)" (...)
error LNK2001: ^ "public: wchar_t const * __thiscall pugi::xml_node::name(void)const " (...)
error LNK2019: ^ "public: wchar_t const * __thiscall pugi::xml_attribute::value(void)const " (...) referenced in function "public: void __thiscall Dae_Node::SetXmlNode(class pugi::xml_node &)" (...)
error LNK2019: ^ "public: class pugi::xml_attribute __thiscall pugi::xml_node::attribute(wchar_t const *)const " (...) referenced in function "public: void __thiscall Dae_Node::SetXmlNode(class pugi::xml_node &)" (...)

我尝试过的事情:

  • 显式实例化我的模板类。
  • 将 PugiXml 源代码与测试项目链接(目前与我正在构建的静态库一起使用)
  • 将 PugiXml 构建为静态库并在我的 lib 项目和测试项目中引用它
  • 写作什么都不做的功能代替了我的纯虚函数。
  • 提供根本不引用 pugixml 的默认构造函数

在过去的两天里,这一直让我发疯,我真的不知道该怎么办。如果有人可以给我任何指导,我将不胜感激!

编辑:值得注意的是,创建一个使用 pugixml 编译和测试的简单静态库很好,所以我编写模板和类的方式可能有问题?

4

1 回答 1

0

从错误消息看来,您设置的 PUGIXML_WCHAR_MODE 不一致。

您很可能在项目配置中设置它,并按原样使用来自 pugixml 分发中的 scripts/ 文件夹中的捆绑 vcproj 文件之一。

此定义控制 pugixml 中使用的字符类型(char 或 wchar_t);您必须为 pugixml.cpp 和使用 pugixml 的代码以相同的方式设置它 - 建议在 pugiconfig.hpp 中设置它,或者确保它在所有具有包含 pugixml 的源文件的项目中处于打开状态.hpp。在您的情况下,如果您不想修改 pugiconfig.hpp,则必须将 vcproj 更改为 pugixml 静态库。

于 2012-01-17T05:33:50.810 回答