-pthreadTrying to build the sample code for the DomParse given in the manual gives me error messages of the form:
-I/usr/include/glib-2.0
-I/usr/lib/x86_64-linux-gnu/glib-2.0/include
-I/usr/include/libxml++-2.6
-I/usr/lib/libxml++-2.6/include
-I/usr/include/libxml2
-I/usr/include/glibmm-2.4
-I/usr/lib/glibmm-2.4/include
-I/usr/include/sigc++-2.0
-I/usr/lib/sigc++-2.0/include
-pthread -L/usr/lib/x86_64-linux-gnu
-lxml++-2.6
-lxml2
-lglibmm-2.4
-lgobject-2.0
-lsigc-2.0
-lgthread-2.0
-lrt correct
-lglib-2.0
main.cpp|19|undefined reference to `typeinfo for xmlpp::ContentNode'
main.cpp|23|undefined reference to `xmlpp::ContentNode::is_white_space() const'
main.cpp|31|undefined reference to `Glib::operator<<(std::basic_ostream<char, std::char_traits<char> >&, Glib::ustring const&)'
Environment:Can you kindly suggest what I may be doing wrong or missing?
gcc version 4.5.2
Code::Blocks 10.05
Ubuntu 11.04
--
-Akanksh Vashisth
||=== trials_01, Debug ===| obj/Debug/main.o||In function `print_node(xmlpp::Node const*, unsigned int)':| /home/akanksh/Documents/codeblocks/trials_01/main.cpp|19|undefined reference to `typeinfo for xmlpp::ContentNode'| /home/akanksh/Documents/codeblocks/trials_01/main.cpp|19|undefined reference to `typeinfo for xmlpp::Node'| /home/akanksh/Documents/codeblocks/trials_01/main.cpp|20|undefined reference to `typeinfo for xmlpp::TextNode'| /home/akanksh/Documents/codeblocks/trials_01/main.cpp|20|undefined reference to `typeinfo for xmlpp::Node'| /home/akanksh/Documents/codeblocks/trials_01/main.cpp|21|undefined reference to `typeinfo for xmlpp::CommentNode'| /home/akanksh/Documents/codeblocks/trials_01/main.cpp|21|undefined reference to `typeinfo for xmlpp::Node'| /home/akanksh/Documents/codeblocks/trials_01/main.cpp|23|undefined reference to `xmlpp::ContentNode::is_white_space() const'| /home/akanksh/Documents/codeblocks/trials_01/main.cpp|26|undefined reference to `xmlpp::Node::get_name() const'| /home/akanksh/Documents/codeblocks/trials_01/main.cpp|28|undefined reference to `Glib::ustring::empty() const'| /home/akanksh/Documents/codeblocks/trials_01/main.cpp|31|undefined reference to `xmlpp::Node::get_name() const'| /home/akanksh/Documents/codeblocks/trials_01/main.cpp|31|undefined reference to `Glib::operator<<(std::basic_ostream<char, std::char_traits<char> >&, Glib::ustring const&)'| /home/akanksh/Documents/codeblocks/trials_01/main.cpp|31|undefined reference to `Glib::ustring::~ustring()'| /home/akanksh/Documents/codeblocks/trials_01/main.cpp|32|undefined reference to `Glib::operator<<(std::basic_ostream<char, std::char_traits<char> >&, Glib::ustring const&)'| /home/akanksh/Documents/codeblocks/trials_01/main.cpp|44|undefined reference to `xmlpp::ContentNode::get_content() const'| /home/akanksh/Documents/codeblocks/trials_01/main.cpp|44|undefined reference to `Glib::operator<<(std::basic_ostream<char, std::char_traits<char> >&, Glib::ustring const&)'| /home/akanksh/Documents/codeblocks/trials_01/main.cpp|44|undefined reference to `Glib::ustring::~ustring()'| /home/akanksh/Documents/codeblocks/trials_01/main.cpp|49|undefined reference to `xmlpp::ContentNode::get_content() const'| /home/akanksh/Documents/codeblocks/trials_01/main.cpp|49|undefined reference to `Glib::operator<<(std::basic_ostream<char, std::char_traits<char> >&, Glib::ustring const&)'| /home/akanksh/Documents/codeblocks/trials_01/main.cpp|49|undefined reference to `Glib::ustring::~ustring()'| /home/akanksh/Documents/codeblocks/trials_01/main.cpp|54|undefined reference to `xmlpp::ContentNode::get_content() const'| /home/akanksh/Documents/codeblocks/trials_01/main.cpp|54|undefined reference to `Glib::operator<<(std::basic_ostream<char, std::char_traits<char> >&, Glib::ustring const&)'| /home/akanksh/Documents/codeblocks/trials_01/main.cpp|54|undefined reference to `Glib::ustring::~ustring()'| /home/akanksh/Documents/codeblocks/trials_01/main.cpp|56|undefined reference to `typeinfo for xmlpp::Element'| /home/akanksh/Documents/codeblocks/trials_01/main.cpp|56|undefined reference to `typeinfo for xmlpp::Node'| /home/akanksh/Documents/codeblocks/trials_01/main.cpp|62|undefined reference to `xmlpp::Node::get_line() const'| /home/akanksh/Documents/codeblocks/trials_01/main.cpp|65|undefined reference to `xmlpp::Element::get_attributes() const'| /home/akanksh/Documents/codeblocks/trials_01/main.cpp|70|undefined reference to `xmlpp::Attribute::get_value() const'| /home/akanksh/Documents/codeblocks/trials_01/main.cpp|70|undefined reference to `xmlpp::Attribute::get_name() const'| /home/akanksh/Documents/codeblocks/trials_01/main.cpp|70|undefined reference to `Glib::operator<<(std::basic_ostream<char, std::char_traits<char> >&, Glib::ustring const&)'| /home/akanksh/Documents/codeblocks/trials_01/main.cpp|70|undefined reference to `Glib::operator<<(std::basic_ostream<char, std::char_traits<char> >&, Glib::ustring const&)'| /home/akanksh/Documents/codeblocks/trials_01/main.cpp|70|undefined reference to `Glib::ustring::~ustring()'| /home/akanksh/Documents/codeblocks/trials_01/main.cpp|70|undefined reference to `Glib::ustring::~ustring()'| /home/akanksh/Documents/codeblocks/trials_01/main.cpp|73|undefined reference to `Glib::ustring::ustring()'| /home/akanksh/Documents/codeblocks/trials_01/main.cpp|73|undefined reference to `Glib::ustring::ustring(char const*)'| /home/akanksh/Documents/codeblocks/trials_01/main.cpp|73|undefined reference to `xmlpp::Element::get_attribute(Glib::ustring const&, Glib::ustring const&) const'| /home/akanksh/Documents/codeblocks/trials_01/main.cpp|73|undefined reference to `Glib::ustring::~ustring()'| /home/akanksh/Documents/codeblocks/trials_01/main.cpp|73|undefined reference to `Glib::ustring::~ustring()'| /home/akanksh/Documents/codeblocks/trials_01/main.cpp|76|undefined reference to `xmlpp::Attribute::get_value() const'| /home/akanksh/Documents/codeblocks/trials_01/main.cpp|76|undefined reference to `Glib::operator<<(std::basic_ostream<char, std::char_traits<char> >&, Glib::ustring const&)'| /home/akanksh/Documents/codeblocks/trials_01/main.cpp|76|undefined reference to `Glib::ustring::~ustring()'| /home/akanksh/Documents/codeblocks/trials_01/main.cpp|84|undefined reference to `Glib::ustring::ustring()'| /home/akanksh/Documents/codeblocks/trials_01/main.cpp|84|undefined reference to `xmlpp::Node::get_children(Glib::ustring const&) const'| /home/akanksh/Documents/codeblocks/trials_01/main.cpp|84|undefined reference to `Glib::ustring::~ustring()'| /home/akanksh/Documents/codeblocks/trials_01/main.cpp|26|undefined reference to `Glib::ustring::~ustring()'| /home/akanksh/Documents/codeblocks/trials_01/main.cpp|31|undefined reference to `Glib::ustring::~ustring()'| /home/akanksh/Documents/codeblocks/trials_01/main.cpp|44|undefined reference to `Glib::ustring::~ustring()'| /home/akanksh/Documents/codeblocks/trials_01/main.cpp|49|undefined reference to `Glib::ustring::~ustring()'| obj/Debug/main.o:/home/akanksh/Documents/codeblocks/trials_01/main.cpp|54|more undefined references to `Glib::ustring::~ustring()' follow| obj/Debug/main.o||In function `main':| /home/akanksh/Documents/codeblocks/trials_01/main.cpp|102|undefined reference to `xmlpp::DomParser::DomParser()'| /home/akanksh/Documents/codeblocks/trials_01/main.cpp|103|undefined reference to `xmlpp::Parser::set_validate(bool)'| ||More errors follow but not being shown.| ||Edit the max errors limit in compiler options...| ||=== Build finished: 50 errors, 0 warnings ===|
#ifdef HAVE_CONFIG_H #include <config.h> #endif #include <libxml++/libxml++.h> #include <iostream> void print_indentation(unsigned int indentation) { for(unsigned int i = 0; i < indentation; ++i) std::cout << " "; } void print_node(const xmlpp::Node* node, unsigned int indentation = 0) { std::cout << std::endl; //Separate nodes by an empty line. const xmlpp::ContentNode* nodeContent = dynamic_cast<const xmlpp::ContentNode*>(node); const xmlpp::TextNode* nodeText = dynamic_cast<const xmlpp::TextNode*>(node); const xmlpp::CommentNode* nodeComment = dynamic_cast<const xmlpp::CommentNode*>(node); if(nodeText && nodeText->is_white_space()) //Let's ignore the indenting - you don't always want to do this. return; Glib::ustring nodename = node->get_name(); if(!nodeText && !nodeComment && !nodename.empty()) //Let's not say "name: text". { print_indentation(indentation); std::cout << "Node name = " << node->get_name() << std::endl; std::cout << "Node name = " << nodename << std::endl; } else if(nodeText) //Let's say when it's text. - e.g. let's say what that white space is. { print_indentation(indentation); std::cout << "Text Node" << std::endl; } //Treat the various node types differently: if(nodeText) { print_indentation(indentation); std::cout << "text = \"" << nodeText->get_content() << "\"" << std::endl; } else if(nodeComment) { print_indentation(indentation); std::cout << "comment = " << nodeComment->get_content() << std::endl; } else if(nodeContent) { print_indentation(indentation); std::cout << "content = " << nodeContent->get_content() << std::endl; } else if(const xmlpp::Element* nodeElement = dynamic_cast<const xmlpp::Element*>(node)) { //A normal Element node: //line() works only for ElementNodes. print_indentation(indentation); std::cout << " line = " << node->get_line() << std::endl; //Print attributes: const xmlpp::Element::AttributeList& attributes = nodeElement->get_attributes(); for(xmlpp::Element::AttributeList::const_iterator iter = attributes.begin(); iter != attributes.end(); ++iter) { const xmlpp::Attribute* attribute = *iter; print_indentation(indentation); std::cout << " Attribute " << attribute->get_name() << " = " << attribute->get_value() << std::endl; } const xmlpp::Attribute* attribute = nodeElement->get_attribute("title"); if(attribute) { std::cout << "title found: =" << attribute->get_value() << std::endl; } } if(!nodeContent) { //Recurse through child nodes: xmlpp::Node::NodeList list = node->get_children(); for(xmlpp::Node::NodeList::iterator iter = list.begin(); iter != list.end(); ++iter) { print_node(*iter, indentation + 2); //recursive } } } int main(int argc, char* argv[]) { std::string filepath; if(argc > 1 ) filepath = argv[1]; //Allow the user to specify a different XML file to parse. else filepath = "example.xml"; try { xmlpp::DomParser parser; parser.set_validate(); parser.set_substitute_entities(); //We just want the text to be resolved/unescaped automatically. parser.parse_file(filepath); if(parser) { //Walk the tree: const xmlpp::Node* pNode = parser.get_document()->get_root_node(); //deleted by DomParser. print_node(pNode); } } catch(const std::exception& ex) { std::cout << "Exception caught: " << ex.what() << std::endl; } return 0; }
Attachment:
trials_01.cbp
Description: application/codeblocks