boost/property_tree/xml_parser.hpp:没有这样的文件或目录
我已经安装了 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您肯定需要让编译器知道在哪里可以找到 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 usestd::cout
, or sayusing std::cout;
orusing namespace std;
... not mentioning the#include <iostream>
. Plus,return
statement inmain
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!
我不认为 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.
我在我的机器上发现了一个可怕的解决方案。 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在内的所有丢失的软件包都回来了并且可以安装。这样就可以彻底解决问题。所以你有两个问题之一:
要么
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,