繁体   English   中英

Boost lib 似乎缺少 hpp 文件?

[英]Boost lib appears to be missing hpp files?

我正在尝试编译需要 Boost 的 C++ 项目。 我从 web 站点下载了最新版本,并将适当的文件复制到适当的 libs 文件夹(我使用的是 MinGW)。 当我编译时,我得到这个错误:

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的工作副本,但我不必手动移动代码文件。

解决方案

我已将 boost 复制到错误的文件夹中。

在没有安装库的情况下尝试将 boost 与 C++ 应用程序一起使用时,我在 Ubuntu 12.10 上收到此错误:

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.

从这段代码:

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

我在 Ubuntu 12.10 上,所以我这样安装了 Boost:

sudo apt-get install libboost-all-dev

然后在重新编译时,它可以工作了,现在我可以使用 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;
    }
}

打印三个单词token , test , string

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

/path/to/boost/boost_1_47_0

并不是

/path/to/boost/boost_1_47_0/boost

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM