RapidXML:无法打印 - 编译时错误
RapidXML: Unable to print - Compile-time Error
我正在尝试使用我的 C++ 应用程序中的 RapidXML 库在控制台中打印 XML 文档数据。
我正在遵循 RapidXML 手册 link here,但我遇到了编译时错误。
这是我的 C++ 代码:
#include <iostream>
#include "rapidxml.hpp"
#include "rapidxml_utils.hpp"
#include "rapidxml_print.hpp"
int main() {
rapidxml::file<> xmlFile("beerJournal.xml");
rapidxml::xml_document<> doc;
doc.parse<0>(xmlFile.data());
std::cout << doc;
return 0;
}
错误如下:
rapidxml_print.hpp:115: error: ‘print_children’ was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive]
out = print_children(out, node, flags, indent);
~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
rapidxml_print.hpp:169: ‘template<class OutIt, class Ch> OutIt rapidxml::internal::print_children(OutIt, const rapidxml::xml_node<Ch>*, int, int)’ declared here, later in the translation unit
inline OutIt print_children(OutIt out, const xml_node<Ch> *node, int flags, int indent)
^~~~~~~~~~~~~~
Obs.: 我已经尝试了手册中描述的其他两种 RapidXML 打印方法(link 以上)。
我的设置:
- Ubuntu 19 x64
- G++ 8.3.0
- 快速XML 1.13
- Qt Creator IDE 4.11.0
- Qt 5.14.0
我过去也遇到过同样的问题。 this SO answer 中介绍的解决方法从那时起对我所有的 GCC 构建都非常有效。
总结另一个答案的信息:它归结为在 GCC 4.7 中进行的名称查找更改。解决方法包括创建一个名为 rapidxml_ext.hpp
的文件,其中包含以下内容。然后在您的客户端 application/library.
中包含 rapidxml_ext.hpp
rapidxml_ext.hpp
#pragma once
#include "rapidxml.hpp"
// Adding declarations to make it compatible with gcc 4.7 and greater
// See
namespace rapidxml {
namespace internal {
template <class OutIt, class Ch>
inline OutIt print_children(OutIt out, const xml_node<Ch>* node, int flags, int indent);
template <class OutIt, class Ch>
inline OutIt print_attributes(OutIt out, const xml_node<Ch>* node, int flags);
template <class OutIt, class Ch>
inline OutIt print_data_node(OutIt out, const xml_node<Ch>* node, int flags, int indent);
template <class OutIt, class Ch>
inline OutIt print_cdata_node(OutIt out, const xml_node<Ch>* node, int flags, int indent);
template <class OutIt, class Ch>
inline OutIt print_element_node(OutIt out, const xml_node<Ch>* node, int flags, int indent);
template <class OutIt, class Ch>
inline OutIt print_declaration_node(OutIt out, const xml_node<Ch>* node, int flags, int indent);
template <class OutIt, class Ch>
inline OutIt print_comment_node(OutIt out, const xml_node<Ch>* node, int flags, int indent);
template <class OutIt, class Ch>
inline OutIt print_doctype_node(OutIt out, const xml_node<Ch>* node, int flags, int indent);
template <class OutIt, class Ch>
inline OutIt print_pi_node(OutIt out, const xml_node<Ch>* node, int flags, int indent);
}
}
#include "rapidxml_print.hpp"
我正在尝试使用我的 C++ 应用程序中的 RapidXML 库在控制台中打印 XML 文档数据。
我正在遵循 RapidXML 手册 link here,但我遇到了编译时错误。
这是我的 C++ 代码:
#include <iostream>
#include "rapidxml.hpp"
#include "rapidxml_utils.hpp"
#include "rapidxml_print.hpp"
int main() {
rapidxml::file<> xmlFile("beerJournal.xml");
rapidxml::xml_document<> doc;
doc.parse<0>(xmlFile.data());
std::cout << doc;
return 0;
}
错误如下:
rapidxml_print.hpp:115: error: ‘print_children’ was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive]
out = print_children(out, node, flags, indent);
~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
rapidxml_print.hpp:169: ‘template<class OutIt, class Ch> OutIt rapidxml::internal::print_children(OutIt, const rapidxml::xml_node<Ch>*, int, int)’ declared here, later in the translation unit
inline OutIt print_children(OutIt out, const xml_node<Ch> *node, int flags, int indent)
^~~~~~~~~~~~~~
Obs.: 我已经尝试了手册中描述的其他两种 RapidXML 打印方法(link 以上)。
我的设置:
- Ubuntu 19 x64
- G++ 8.3.0
- 快速XML 1.13
- Qt Creator IDE 4.11.0
- Qt 5.14.0
我过去也遇到过同样的问题。 this SO answer 中介绍的解决方法从那时起对我所有的 GCC 构建都非常有效。
总结另一个答案的信息:它归结为在 GCC 4.7 中进行的名称查找更改。解决方法包括创建一个名为 rapidxml_ext.hpp
的文件,其中包含以下内容。然后在您的客户端 application/library.
rapidxml_ext.hpp
rapidxml_ext.hpp
#pragma once
#include "rapidxml.hpp"
// Adding declarations to make it compatible with gcc 4.7 and greater
// See
namespace rapidxml {
namespace internal {
template <class OutIt, class Ch>
inline OutIt print_children(OutIt out, const xml_node<Ch>* node, int flags, int indent);
template <class OutIt, class Ch>
inline OutIt print_attributes(OutIt out, const xml_node<Ch>* node, int flags);
template <class OutIt, class Ch>
inline OutIt print_data_node(OutIt out, const xml_node<Ch>* node, int flags, int indent);
template <class OutIt, class Ch>
inline OutIt print_cdata_node(OutIt out, const xml_node<Ch>* node, int flags, int indent);
template <class OutIt, class Ch>
inline OutIt print_element_node(OutIt out, const xml_node<Ch>* node, int flags, int indent);
template <class OutIt, class Ch>
inline OutIt print_declaration_node(OutIt out, const xml_node<Ch>* node, int flags, int indent);
template <class OutIt, class Ch>
inline OutIt print_comment_node(OutIt out, const xml_node<Ch>* node, int flags, int indent);
template <class OutIt, class Ch>
inline OutIt print_doctype_node(OutIt out, const xml_node<Ch>* node, int flags, int indent);
template <class OutIt, class Ch>
inline OutIt print_pi_node(OutIt out, const xml_node<Ch>* node, int flags, int indent);
}
}
#include "rapidxml_print.hpp"