O
O
Olegofr3n772020-11-11 19:33:11
C++ / C#
Olegofr3n77, 2020-11-11 19:33:11

Error while compiling project using boost?

Error while compiling project with boost
Program code:

#include <boost/beast.hpp>
#include <boost/asio/connect.hpp>
#include <boost/asio/ip/tcp.hpp>
#include <string>
#include <iostream>

using namespace std;
namespace http = boost::beast::http;

int main(int argc, char* argv[])
{
    boost::asio::io_context io;
    boost::asio::ip::tcp::resolver resolver(io);
    boost::asio::ip::tcp::socket socket(io);

    boost::asio::connect(socket, resolver.resolve("google.com", "80"));

    http::request<http::string_body> req(http::verb::get, "/", 11);

    req.set(http::field::host, "google.com");
    req.set(http::field::user_agent, BOOST_BEAST_VERSION_STRING);

    http::write(socket, req);

    string response;
    {
        boost::beast::flat_buffer buffer;
        http::response<http::dynamic_body> res;
        http::read(socket, buffer, res);
        response = boost::beast::buffers_to_string(res.body().data());
    }

    socket.shutdown(boost::asio::ip::tcp::socket::shutdown_both);

    cout << response;

    return 0;
}


The command with which I collected:
g++ -I Z:\boost_1_74_0 -L Z:\boost_1_74_0\stage\lib main.cpp -o main


And the error itself:
In file included from Z:\boost_1_74_0/boost/beast/websocket/detail/prng.hpp:47:0,
                 from Z:\boost_1_74_0/boost/beast/websocket/detail/hybi13.ipp:15,
                 from Z:\boost_1_74_0/boost/beast/websocket/detail/hybi13.hpp:45,
                 from Z:\boost_1_74_0/boost/beast/websocket/stream.hpp:19,
                 from Z:\boost_1_74_0/boost/beast/websocket.hpp:18,
                 from Z:\boost_1_74_0/boost/beast.hpp:18,
                 from main.cpp:3:
Z:\boost_1_74_0/boost/beast/websocket/detail/prng.ipp: In function 'uint32_t boost::beast::websocket::detail::secure_generate()':
Z:\boost_1_74_0/boost/beast/websocket/detail/prng.ipp:92:14: error: 'mutex' in namespace 'std' does not name a type
         std::mutex mtx;
              ^~~~~
Z:\boost_1_74_0/boost/beast/websocket/detail/prng.ipp: In member function 'uint32_t boost::beast::websocket::detail::secure_generate()::generator::operator()()':
Z:\boost_1_74_0/boost/beast/websocket/detail/prng.ipp:87:29: error: 'mutex' is not a member of 'std'
             std::lock_guard<std::mutex> guard{mtx};
                             ^~~
Z:\boost_1_74_0/boost/beast/websocket/detail/prng.ipp:87:29: note: suggested alternative:
In file included from Z:\boost_1_74_0/boost/asio/execution/blocking_adaptation.hpp:20:0,
                 from Z:\boost_1_74_0/boost/asio/execution.hpp:22,
                 from Z:\boost_1_74_0/boost/asio/system_executor.hpp:20,
                 from Z:\boost_1_74_0/boost/asio/associated_executor.hpp:22,
                 from Z:\boost_1_74_0/boost/beast/core/detail/bind_handler.hpp:16,
                 from Z:\boost_1_74_0/boost/beast/core/bind_handler.hpp:14,
                 from Z:\boost_1_74_0/boost/beast/core/async_base.hpp:14,
                 from Z:\boost_1_74_0/boost/beast/core.hpp:15,
                 from Z:\boost_1_74_0/boost/beast.hpp:15,
                 from main.cpp:3:
Z:\boost_1_74_0/boost/asio/detail/mutex.hpp:39:19: note:   'boost::asio::detail::mutex'
 typedef win_mutex mutex;
                   ^~~~~
In file included from Z:\boost_1_74_0/boost/beast/websocket/detail/prng.hpp:47:0,
                 from Z:\boost_1_74_0/boost/beast/websocket/detail/hybi13.ipp:15,
                 from Z:\boost_1_74_0/boost/beast/websocket/detail/hybi13.hpp:45,
                 from Z:\boost_1_74_0/boost/beast/websocket/stream.hpp:19,
                 from Z:\boost_1_74_0/boost/beast/websocket.hpp:18,
                 from Z:\boost_1_74_0/boost/beast.hpp:18,
                 from main.cpp:3:
Z:\boost_1_74_0/boost/beast/websocket/detail/prng.ipp:87:29: error: 'mutex' is not a member of 'std'
             std::lock_guard<std::mutex> guard{mtx};
                             ^~~
Z:\boost_1_74_0/boost/beast/websocket/detail/prng.ipp:87:29: note: suggested alternative:
In file included from Z:\boost_1_74_0/boost/asio/execution/blocking_adaptation.hpp:20:0,
                 from Z:\boost_1_74_0/boost/asio/execution.hpp:22,
                 from Z:\boost_1_74_0/boost/asio/system_executor.hpp:20,
                 from Z:\boost_1_74_0/boost/asio/associated_executor.hpp:22,
                 from Z:\boost_1_74_0/boost/beast/core/detail/bind_handler.hpp:16,
                 from Z:\boost_1_74_0/boost/beast/core/bind_handler.hpp:14,
                 from Z:\boost_1_74_0/boost/beast/core/async_base.hpp:14,
                 from Z:\boost_1_74_0/boost/beast/core.hpp:15,
                 from Z:\boost_1_74_0/boost/beast.hpp:15,
                 from main.cpp:3:
Z:\boost_1_74_0/boost/asio/detail/mutex.hpp:39:19: note:   'boost::asio::detail::mutex'
 typedef win_mutex mutex;

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question