C++ Boost lib 似乎缺少 hpp 文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7021371/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 16:22:28  来源:igfitidea点击:

Boost lib appears to be missing hpp files?

c++boostmingw

提问by David Perry

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:

我正在尝试编译一个需要 Boost 的 C++ 项目。我从网站下载了最新版本并将相应的文件复制到相应的 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.

I can find a working copy of foreach.hppbut I shouldn't have to move code files manually.

我可以找到 的工作副本,foreach.hpp但我不必手动移动代码文件。

Solution

解决方案

I had copied boost to the wrong folder.

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

采纳答案by Nicola Musatti

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_0directory, but leaving out the boostone, e.g.

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

/path/to/boost/boost_1_47_0

and not

并不是

/path/to/boost/boost_1_47_0/boost

回答by Eric Leschinski

I got this error on Ubuntu 12.10 when trying to use boost with a C++ application without the libraries installed:

我在 Ubuntu 12.10 上尝试在未安装库的情况下对 C++ 应用程序使用 boost 时遇到此错误:

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:

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

sudo apt-get install libboost-all-dev

Then on recompile, it works and now I can use boost!

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

打印三个单词token, test,string

回答by adivis12

On Fedora and Centos yum install -y boostand yum install -y boost-devel

在 Fedora 和 Centosyum install -y boost以及yum install -y boost-devel