Boost lib appears to be missing hpp files?
I'm trying to compile a C++ p开发者_开发技巧roject that requires Boost. I downloaded the latest build from the web site and copied the appropriate files to the appropriate libs folder (I'm using MinGW). When I compile, I'm get this error:
In file included from main.cpp:4:0:
headers.h:59:29: fatal error: boost/foreach.hpp: No such file or directory
compilation terminated.
I can find a working copy of foreach.hpp
but I shouldn't have to move code files manually.
Solution
I had copied boost to the wrong folder.
I got this error on Ubuntu 12.10 when trying to use boost with a C++ application without the libraries installed:
el@apollo:~/foo8/33_parse_file$ g++ -o s s.cpp
s.cpp:3:29: fatal error: boost/foreach.hpp: No such file or directory
compilation terminated.
From this code:
#include <iostream>
#include <boost/foreach.hpp>
#include <boost/tokenizer.hpp>
using namespace std;
int main(){
cout << "hi";
}
I'm on Ubuntu 12.10 so I installed Boost like this:
sudo apt-get install libboost-all-dev
Then on recompile, it works and now I can use boost!
#include <iostream>
#include <string>
#include <boost/foreach.hpp>
#include <boost/tokenizer.hpp>
using namespace std;
using namespace boost;
int main(int argc, char** argv)
{
string text = "token test\tstring";
char_separator<char> sep(" \t");
tokenizer<char_separator<char> > tokens(text, sep);
BOOST_FOREACH(string t, tokens)
{
cout << t << "." << endl;
}
}
Prints the three words token
, test
, string
You should make sure that your include path is set correctly. Assuming you downloaded Boost 1.47.0 your path should contain the location to your Boost installation up to the boost_1_47_0
directory, but leaving out the boost
one, e.g.
/path/to/boost/boost_1_47_0
and not
/path/to/boost/boost_1_47_0/boost
On Fedora and Centos yum install -y boost
and yum install -y boost-devel
精彩评论