简体   繁体   English

boost / property_tree / xml_parser.hpp:没有这样的文件或目录

[英]boost/property_tree/xml_parser.hpp: No such file or directory

I have installed boost_1_41_0 and try to follow some tutorials on xml parsing: 我已经安装了boost_1_41_0并尝试按照一些关于xml解析的教程:

#include <boost/property_tree/ptree.hpp>
int main(){
  using boost::property_tree::ptree;
  ptree pt;
  cout<<"Here is an XML test!\n";
  return 0;
}

But the problem is that the boost can not find the required header: 但问题是提升无法找到所需的标题:

gcc.compile.c++ bin/gcc-4.6.0/debug/main.o
main.cpp:1:46: fatal error: boost/property_tree/ptree.hpp: No such file or  directory
compilation terminated.

Using "" instead of <> does not help either. 使用“”代替<>也无济于事。 I also tried to pass the option cxxflags=-I/pass/to/this/header - this does not work too. 我也尝试将选项cxxflags = -I / pass /传递给/ this / header - 这也不起作用。 Only if I use the full path to the header - it works, but it then depends on another header file, which it can not find. 只有当我使用标题的完整路径时 - 它才有效,但它依赖于另一个无法找到的头文件。

So how to make boost installation look for its own include directories? 那么如何使boost安装看起来有自己的include目录呢? Thanks. 谢谢。

You definitely need to let compiler know where to find boost headers. 你肯定需要让编译器知道在哪里找到boost头。 However, you have to pass path to the directory in which "boost" directory is located, and not the directory where this include file reside. 但是,您必须将路径传递到“boost”目录所在的目录,而不是该包含文件所在的目录。 So, for example, if your boost headers are in /opt/boost/1.47.0/include and your file is in /opt/boost/1.47.0/include/boost/property_tree/ptree.hpp , then you have to pass /opt/boost/1.47.0/include to the compiler using -I : -I/opt/boost/1.47.0/include . 因此,例如,如果您的boost标头位于/opt/boost/1.47.0/include并且您的文件位于/opt/boost/1.47.0/include/boost/property_tree/ptree.hpp ,那么您必须通过/opt/boost/1.47.0/include包含使用-I-I/opt/boost/1.47.0/include的编译器。 Or even better, use -isystem /opt/boost/1.47.0/include so that you don't get warnings from those headers. 或者甚至更好,使用-isystem /opt/boost/1.47.0/include这样就不会从这些标头中收到警告。

And yeah, you forgot that there is no cout in global namespace, you have to use std::cout , or say using std::cout; 是的,你忘记了全局命名空间中没有cout ,你必须使用std::cout ,或者说using std::cout; or using namespace std; using namespace std; ... not mentioning the #include <iostream> . ......没有提到#include <iostream> Plus, return statement in main function is not required in C++, it will return 0 by default, unless you return something else, so you can simply remove that line. 另外,在C ++中不需要main函数中的return语句,默认情况下它将返回0,除非你返回其他内容,所以你可以简单地删除该行。

Hope it helps. 希望能帮助到你。 Good luck! 祝好运!

I don't think that xml_parser.hpp exists in version 1.41, and I see that its also a problem in 1.49 which is on my debian wheezy 7.x machine. 我不认为版本1.41中存在xml_parser.hpp,我发现它在我的debian wheezy 7.x机器上的1.49也是一个问题。 I do see that it is in boost 1.55, so its just a matter of you getting the latest version of boost filesystem to find the missing package. 我确实看到它在boost 1.55中,所以它只是你得到最新版本的boost文件系统来找到丢失的包。

I found out a scary solution on my machine. 我在机器上发现了一个可怕的解决方案。 boost 1.49 does contain xml_parser.hpp in boost1.49-dev as shown by libboost1.49-dev: /usr/include/boost/property_tree/xml_parser.hpp boost 1.49确实包含boost1.49-dev中的xml_parser.hpp,如libboost1.49-dev所示:/usr/include/boost/property_tree/xml_parser.hpp

However it could not be accessed or downloaded on my machine because of a strange error caused by a spotify repository installed on my machine. 但是由于我的机器上安装了spotify存储库导致的奇怪错误,无法在我的机器上访问或下载它。 What is even stranger about this is that the security fixes come in every day and install correctly. 更奇怪的是,安全修复程序每天都会进入并正确安装。 When I cleaned out the sources.list file and ran apt-get clean and then apt-get update, I found that all the missing packages including libboost1.49-dev came back and where then installable. 当我清理sources.list文件并运行apt-get clean然后apt-get update时,我发现所有丢失的软件包包括libboost1.49-dev都回来了,然后可以安装。 This then fixes the problem completely. 然后,这完全解决了问题。 So you have one of two problems: 所以你有两个问题之一:

Either, 要么,

  1. your system is slightly mangled. 你的系统有点受损。 To test whether this assertion is correct, run apt-get clean and then apt-get update. 要测试此断言是否正确,请运行apt-get clean,然后运行apt-get update。 If you obtain lots of repository errors then you know how to fix the problem. 如果您获得了大量存储库错误,那么您就知道如何解决问题。 Remove the offending repositories and rerun apt-get clean and update. 删除有问题的存储库并重新运行apt-get clean并进行更新。
  2. Or, its just the case that you have not installed libboost1.49-dev to obtain the xml_parser.hpp. 或者,只是您没有安装libboost1.49-dev来获取xml_parser.hpp。

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

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