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

发布于 2024-12-03 08:28:41 字数 603 浏览 0 评论 0原文

我已经安装了 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;
}

但问题是 boost 找不到所需的标头:

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.

使用“”而不是 <>也没有帮助。我还尝试传递选项 cxxflags=-I/pass/to/this/header - 这也不起作用。仅当我使用标头的完整路径时 - 它才有效,但它依赖于另一个它无法找到的头文件。

那么如何让boost安装寻找自己的include目录呢?谢谢。

I have installed boost_1_41_0 and try to follow some tutorials on xml parsing:

#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. 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? Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

诗笺 2024-12-10 08:28:41

您肯定需要让编译器知道在哪里可以找到 boost 标头。但是,您必须将路径传递到“boost”目录所在的目录,而不是此包含文件所在的目录。因此,例如,如果您的 boost 标头位于 /opt/boost/1.47.0/include 中,并且您的文件位于 /opt/boost/1.47.0/include/boost/property_tree 中/ptree.hpp,然后您必须使用 -I/opt/boost/1.47.0/include 传递给编译器: -I/opt/boost/1.47.0/include。或者更好的是,使用 -isystem /opt/boost/1.47.0/include 这样您就不会从这些标头中收到警告。

是的,您忘记了全局命名空间中没有 cout,您必须使用 std::cout,或者说 using std::cout; 或 using namespace std;... 没有提及 #include。另外,在C++中,main函数中的return语句不是必需的,它默认返回0,除非你返回其他东西,所以你可以简单地删除该行。

希望有帮助。祝你好运!

You definitely need to let compiler know where to find boost headers. However, you have to pass path to the directory in which "boost" directory is located, and not the directory where this include file reside. 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. Or even better, use -isystem /opt/boost/1.47.0/include so that you don't get warnings from those headers.

And yeah, you forgot that there is no cout in global namespace, you have to use std::cout, or say using std::cout; or using namespace std;... not mentioning the #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.

Hope it helps. Good luck!

深爱成瘾 2024-12-10 08:28:41

我不认为 xml_parser.hpp 存在于版本 1.41 中,而且我发现它在我的 debian wheezy 7.x 机器上的 1.49 中也是一个问题。我确实看到它是 boost 1.55,所以只需获取最新版本的 boost 文件系统即可找到丢失的包。

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. 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.

兲鉂ぱ嘚淚 2024-12-10 08:28:41

我在我的机器上发现了一个可怕的解决方案。 boost 1.49 确实在 boost1.49-dev 中包含 xml_parser.hpp,如下所示
libboost1.49-dev:/usr/include/boost/property_tree/xml_parser.hpp

但是,由于我的计算机上安装的 Spotify 存储库导致出现奇怪的错误,因此无法在我的计算机上访问或下载它。更奇怪的是,安全修复程序每天都会出现并正确安装。当我清理了sources.list文件并运行apt-get clean,然后运行apt-get update时,我发现包括libboost1.49-dev在内的所有丢失的软件包都回来了并且可以安装。这样就可以彻底解决问题。所以你有两个问题之一:

要么

  1. 你的系统有轻微损坏。要测试此断言是否正确,请运行 apt-get clean,然后运行 ​​apt-get update。如果您收到大量存储库错误,那么您就知道如何解决问题。删除有问题的存储库并重新运行 apt-get clean 和 update。
  2. 或者,只是您没有安装libboost1.49-dev来获取xml_parser.hpp。

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

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. 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. 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. 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.
  2. Or, its just the case that you have not installed libboost1.49-dev to obtain the xml_parser.hpp.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文