boost/beast/core.hpp: 没有那个文件或目录

boost/beast/core.hpp: There is no such file or directory

我需要用C ++写一个服务器,今天我通过 sudo apt-get install -f libboost-all-dev 下载了Boost,但是这个示例代码无法编译。写入错误: boost.cpp:16:32: 致命错误: boost/beast/core.hpp: 没有这样的文件或目录 #include

而且/usr/include/boost/没有“野兽”文件夹

如何解决问题?我抽了很多次

$ grep BOOST_VERSION  /usr/include/boost/version.hpp

#ifndef BOOST_VERSION_HPP
#define BOOST_VERSION_HPP
//  BOOST_VERSION % 100 is the patch level
//  BOOST_VERSION / 100 % 1000 is the minor version
//  BOOST_VERSION / 100000 is the major version
#define BOOST_VERSION 106501
//  BOOST_LIB_VERSION must be defined to be the same as BOOST_VERSION


$ grep VERSION /etc/os-release

VERSION="18.04.5 LTS (Bionic Beaver)"
VERSION_ID="18.04"
VERSION_CODENAME=bionic 

http_server_sync.cpp https://www.boost.org/doc/libs/1_75_0/libs/beast/doc/html/beast/examples.html#beast.examples.clients

版本老了,如何正确更新?

更新:

文件出现后,我将 Ubuntu 更新到 20.4,但链接也有问题。删除过去的库文件: sudo apt remove libboost-all-dev sudo apt autoremove

然后我从官网正常下载了:

$ wget https://boostorg.jfrog.io/artifactory/main/release/1.76.0/source/boost_1_76_0.tar.gz
$ tar xf boost_1_76_0.tar.gz
$ ./bootstrap.sh       
$ ./b2

然后这样链接之后(错误,可能,但是链接了!) 编译示例:

$ g++ boost.cpp -I/home/matroskin/boost_1_76_0 -L/home/matroskin//boost_1_76_0/stage/lib -lboost_system -lpthread```

根据文档,

https://www.boost.org/doc/libs/1_66_0/

Beast
Portable HTTP, WebSocket, and network operations using only C++11 and Boost.Asio
...
First Release 1.66.0

您需要至少升级到 1.66.0

编辑
实际上,您有几个选择

  1. 升级ubuntu版本。是的,有些人认为它有点冒险,可能会导致需要重装系统。
  2. 删除 boost 包,改为从源代码手动安装 boost。这并不难,而且有据可查。

我不使用 ubuntu,无法为您提供更多帮助。我记得我曾经不得不安装一个更新版本的 boost,然后是我的包系统中的那个,这不是一个大问题。此外,beast 是一个仅包含头文件的库,因此您甚至不必编译(boost 的这一部分,但 beast 可能依赖于必须编译的库的其他部分)。

我要重申:从源安装 boost 并不难,而且对您的系统肯定是安全的。