gpt4 book ai didi

html - 对 `htmlcxx::HTML::ParserDom::parseTree(std::string const&)' 的 undefined reference

转载 作者:太空宇宙 更新时间:2023-11-04 13:46:04 25 4
gpt4 key购买 nike

我正在为一个简单的程序使用 htmlcxx 库,但我遇到了一个问题,我搜索了许多其他相关的解决方案,但我的问题仍然是一个问题,希望有人能帮助我,这是我在 Kdevelop 上使用的代码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;
}

这是我在 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**

最佳答案

错误的库路径是它没有链接代码的原因。

关于html - 对 `htmlcxx::HTML::ParserDom::parseTree(std::string const&)' 的 undefined reference ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25915509/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com