1

I am using htmlcxx library for a simple program but I got stuck in a problem, I searched many other related solutions but my problem is still a problem, Hope any one can help me, Here is the code I used in Kdevelop on Ubuntu:

#include <iostream>
#include <string>
#include <htmlcxx/html/ParserDom.h>


using namespace htmlcxx;


int main()
{

  //Parse some html code
  std::string html = "<html><body>hey</body></html>";
  HTML::ParserDom parser;
  tree<HTML::Node> dom= parser.parseTree(html) ;

  //Print whole DOM tree
  std::cout << dom << std::endl;

  //Dump all links in the tree
  tree<HTML::Node>::iterator it = dom.begin();
  tree<HTML::Node>::iterator end = dom.end();
  for (; it != end; ++it)
  {
    if (it->tagName() == "A")
    {
        it->parseAttributes();
        std::cout << it->attribute("href").second;
    }
  }

  //Dump all text of the document
  it = dom.begin();
  end = dom.end();
  for (; it != end; ++it)
  {
    if ((!it->isTag()) && (!it->isComment()))
    {
        std::cout << it->text();
    }
  }

  return 0;
}

And here is the error come when I build it in Kdevelop:

/home/ratior/projects/html/build> make -j2
Scanning dependencies of target html
[100%] Building CXX object CMakeFiles/html.dir/main.o
Linking CXX executable html
CMakeFiles/html.dir/main.o: In function `main':
/home/ratior/projects/html/main.cpp:17: undefined reference to `htmlcxx::HTML::ParserDom::parseTree(std::string const&)'
/home/ratior/projects/html/main.cpp:20: undefined reference to `htmlcxx::HTML::operator<<(std::ostream&, tree<htmlcxx::HTML::Node, std::allocator<tree_node_<htmlcxx::HTML::Node> > > const&)'
/home/ratior/projects/html/main.cpp:29: undefined reference to `htmlcxx::HTML::Node::parseAttributes()'
CMakeFiles/html.dir/main.o: In function `htmlcxx::HTML::ParserDom::ParserDom()':
/usr/local/include/htmlcxx/html/ParserDom.h:14: undefined reference to `vtable for htmlcxx::HTML::ParserDom'
CMakeFiles/html.dir/main.o: In function `htmlcxx::HTML::ParserDom::~ParserDom()':
/usr/local/include/htmlcxx/html/ParserDom.h:15: undefined reference to `vtable for htmlcxx::HTML::ParserDom'
collect2: error: ld returned 1 exit status
make[2]: *** [html] Error 1
make[1]: *** [CMakeFiles/html.dir/all] Error 2
make: *** [all] Error 2
*** Failure: Exit code 2 **strong text**
zneak
  • 134,922
  • 42
  • 253
  • 328
Mehran
  • 308
  • 3
  • 15

1 Answers1

0

Wrong path to the library is the reason why it's not linking the code.

Mehran
  • 308
  • 3
  • 15