puneet
puneet

Reputation: 45

htmlcxx0.84 compilation error

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 ..

Upvotes: 0

Views: 639

Answers (1)

Some programmer dude
Some programmer dude

Reputation: 409404

If your entire command line is

g++ webscrsp.cpp 

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:

g++ webscrsp.cpp -L/path/to/library -Wl,-rpath=/path/to/library -lname_of_library

In the above command line example, /path/to/library is the path to a file named libXXX.a, where XXX is the name_of_library.

In your case, you should look somewhere in /home/lubhavan/htmlcxx-0.84/ to find a file that starts with lib and ends in .a. The /path/to/library is the path where that file is. The name_of_library is the name of the file without the leading lib and trailing .a.

Upvotes: 1

Related Questions