2

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.

ildjarn
  • 62,044
  • 9
  • 127
  • 211
Alex
  • 21
  • 1
  • 2

3 Answers3

6

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!

0

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.

Eamonn Kenny
  • 1,926
  • 18
  • 20
  • 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 – Eamonn Kenny Aug 13 '15 at 10:17
0

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.
Eamonn Kenny
  • 1,926
  • 18
  • 20