I try to use htmlcxx to parse a webpage. The problem is, the example isn’t compileable .
I am getting this when I run g++ webscrsp.cpp:
/tmp/ccHiUM6o.o: In function `main': webscrsp.cpp:(.text+0x86): undefined reference to `htmlcxx::HTML::ParserSax::parse(std::basic_string, std::allocator > const&)' webscrsp.cpp:(.text+0xb8): undefined reference to `htmlcxx::HTML::operator >&, tree > > const&)' /tmp/ccHiUM6o.o: In function `htmlcxx::HTML::ParserDom::ParserDom()': webscrsp.cpp:(.text._ZN7htmlcxx4HTML9ParserDomC1Ev[htmlcxx::HTML::ParserDom::ParserDom()]+0x22): undefined reference to `vtable for htmlcxx::HTML::ParserDom' /tmp/ccHiUM6o.o: In function `htmlcxx::HTML::ParserDom::~ParserDom()': webscrsp.cpp:(.text._ZN7htmlcxx4HTML9ParserDomD1Ev[htmlcxx::HTML::ParserDom::~ParserDom()]+0x16): undefined reference to `vtable for htmlcxx::HTML::ParserDom' collect2: ld returned 1 exit status
my code is
#include <string>
#include <iostream>
#include <sstream>
#include </home/lubhavan/htmlcxx-0.84/html/ParserDom.h>
using namespace std;
using namespace htmlcxx;
int main()
{
string html ="<html > <head> <title > hi iam titile </title> </head> <body> <p> what can i do </p> </body> </html>";
HTML::ParserDom parser;
tree<HTML::Node> dom = parser.parseTree(html) ;
cout << dom <<endl;
cout << endl;
return 0;
}
Please help me as I have to do it very soon. I am unable to get the fault …
Thanks in advance ..
If your entire command line is
then you will get linker error because you don’t link with the library which contain the actual code.
You have to do something like this:
In the above command line example,
/path/to/libraryis the path to a file namedlibXXX.a, whereXXXis thename_of_library.In your case, you should look somewhere in
/home/lubhavan/htmlcxx-0.84/to find a file that starts withliband ends in.a. The/path/to/libraryis the path where that file is. Thename_of_libraryis the name of the file without the leadingliband trailing.a.