Search code examples
c++boostboost-beast

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


I need to write a server in C ++ and today I downloaded Boost via sudo apt-get install-f libboost-all-dev , but this sample code does not compile. Writes an error: boost.cpp:16:32: fatal error: boost/beast/core.hpp: There is no such file or directory #include <boost/beast/core.hpp>

And and /usr/include/boost/ no "beast" folder"

How to solve the problem? I've pumped it many times

$ 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

If the version is old, then how to update correctly?

UPD:

I updated Ubuntu to 20.4, after the files appeared, but there were also problems with linking. Deleted past library files: sudo apt remove libboost-all-dev sudo apt autoremove

then I downloaded it from the official website normally:

$ 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

And after linking so (wrong, probably, but linked!) Compilation example:

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

Solution

  • According to the documentation,

    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

    you need to upgrade to at least 1.66.0

    Edit
    In practice, you have a few options

    1. Upgrade ubuntu release. Yes, some people consider it a bit risky and it may result in the necessity of reinstalling the system.
    2. Remove the boost package and, instead, install boost manually, from the sources. This is not difficult, and is well-documented.

    I don't use ubuntu and I can't help you more. I remember I once had to install a newer version of boost then the one I had in my package system and it was not a big problem. Also, beast is a header-only library, so you'll even won't have to compile (this part of boost, but beast may depend on other parts of the library, that have to be compiled).

    I'll reiterate: installing boost from sources is not that difficult and certainly is safe for your system.