Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Boost lib appears to be missing hpp files?

Tags:

c++

mingw

boost

I'm trying to compile a C++ project 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.

like image 819
David Perry Avatar asked Aug 11 '11 05:08

David Perry


2 Answers

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

like image 155
Eric Leschinski Avatar answered Nov 07 '22 13:11

Eric Leschinski


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
like image 10
Nicola Musatti Avatar answered Nov 07 '22 15:11

Nicola Musatti