繁体   English   中英

未定义引用htmlcxx :: HTML :: ParserDom :: parseTree(std :: string const&)

[英]undefined reference to `htmlcxx::HTML::ParserDom::parseTree(std::string const&)'

我正在使用htmlcxx库编写一个简单的程序,但是我陷入了一个问题,我搜索了许多其他相关的解决方案,但是我的问题仍然是个问题,希望任何人都可以帮助我,这是我在Ubuntu上的Kdevelop中使用的代码:

#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**

库路径错误是未链接代码的原因。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM