2011-08-11 115 views
5

我想编译一个需要Boost的C++项目。我从网站上下载了最新版本,并将相应的文件复制到相应的libs文件夹中(我正在使用MinGW)。当我编译,我得到这个错误:Boost lib似乎缺少hpp文件?

In file included from main.cpp:4:0: 
headers.h:59:29: fatal error: boost/foreach.hpp: No such file or directory 
compilation terminated. 

我能找到的foreach.hpp工作拷贝,但我不应该移动代码文件手动。

解决方案

我抄袭推动了错误的文件夹。

+2

你更新包含路径? –

+1

g ++ -I -c * .cpp – Arunmu

+1

当你说你将它们复制到“适当的libs文件夹”时,那个文件夹会是什么? – janitor048

回答

6

您应该确保您的包含路径设置正确。假设您下载了Boost 1.47.0,您的路径应该包含升级安装到boost_1_47_0目录的位置,但不包括boost之一,例如

/path/to/boost/boost_1_47_0 

,而不是

/path/to/boost/boost_1_47_0/boost 
11

我试图用升压与C没有安装库++应用程序时,在Ubuntu 12.10得到这个错误:

[email protected]:~/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. 

从这个代码:

#include <iostream> 
#include <boost/foreach.hpp> 
#include <boost/tokenizer.hpp> 
using namespace std; 
int main(){ 
    cout << "hi"; 
} 

我在Ubu ntu 12.10所以我安装了这样的升压:

sudo apt-get install libboost-all-dev 

然后在重新编译,它的工作,现在我可以使用提升!

#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; 
    } 
} 

打印三个字tokenteststring

+0

在Ubuntu 12.04上编译CGAL SWIG绑定时,我需要'libboost1.48-all-dev'。 –