Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/142.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ htmlcxx0.84编译错误_C++_Compiler Errors_Html Parsing - Fatal编程技术网

C++ htmlcxx0.84编译错误

C++ htmlcxx0.84编译错误,c++,compiler-errors,html-parsing,C++,Compiler Errors,Html Parsing,我尝试使用htmlcxx解析网页。问题是,该示例不可编译 当我运行g++webcrsp.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): u

我尝试使用
htmlcxx
解析网页。问题是,该示例不可编译

当我运行
g++webcrsp.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 /tmp/ccHiUM6o.o:在函数“main”中: webcrsp.cpp:(.text+0x86):对“htmlcxx::HTML::ParserSax::parse(std::basic_string,std::allocator>const&)”的未定义引用 webcrsp.cpp:(.text+0xb8):对“htmlcxx::HTML::operator>&,tree>>const&”的未定义引用 /tmp/ccHiUM6o.o:在函数“htmlcxx::HTML::ParserDom::ParserDom()”中: webcrsp.cpp:(.text.\u ZN7htmlcxx4HTML9ParserDomC1Ev[htmlcxx::HTML::ParserDom::ParserDom()]+0x22):对“htmlcxx::HTML::ParserDom的vtable”的未定义引用 /tmp/ccHiUM6o.o:在函数“htmlcxx::HTML::ParserDom::~ParserDom()”中: webcrsp.cpp:(.text.\u ZN7htmlcxx4HTML9ParserDomD1Ev[htmlcxx::HTML::ParserDom::~ParserDom()]+0x16):对“htmlcxx::HTML::ParserDom的vtable”的未定义引用 collect2:ld返回了1个退出状态 我的代码是

    #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;
     }
#包括
#包括
#包括
#包括
使用名称空间std;
使用名称空间htmlcxx;
int main()
{
string html=“hi iam titile我能做什么”

”; 语法分析器; treedom=parser.parseTree(html);
cout如果您的整个命令行

g++ webscrsp.cpp 
然后您将得到链接器错误,因为您没有链接到包含实际代码的库

你必须这样做:

g++ webscrsp.cpp -L/path/to/library -Wl,-rpath=/path/to/library -lname_of_library
在上面的命令行示例中,
/path/to/library
是名为
libXXX.a
的文件的路径,其中
XXX
是库的
名称


在您的情况下,您应该查找
/home/lubhavan/htmlcxx-0.84/
中的某个位置,以
lib
开头并以
.a
结尾的文件。
/path/to/library
是该文件所在的路径。
library
名称是不带前导
lib
和尾随
.a的文件名

可能的副本没有扩展名为.lib的文件,但有些文件以lib开头,扩展名为.la或.so…@puneet The
。因此
文件也是一个库,但它是一个动态链接到应用程序的库。其工作原理相同,请使用
-L
设置库所在的路径,然后使用
-L
(小写L)命名要链接的库(不含
lib
.so
)@Joahim Pileborg非常感谢,非常有效:)但我还有一个问题,每次我必须运行teh时,我是否必须在libname中添加此库路径program@puneet更新了我的答案以包含另一个命令行参数,该参数用于设置可执行文件的运行时路径。