我正在使用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**
答案 0 :(得分:0)
错误的图书馆路径是它没有链接代码的原因。