Spook
Spook

Reputation: 311

Cannot convert boost::asio::netdb::errors to std::error_code

I'm trying to compile this code (taken from the cpp-netlib documentation):

#include <boost/network/protocol/http/client.hpp>
#include <iostream>

int main(int argc, char *argv[]) {
    using namespace boost::network;

    if (argc != 2) {
        std::cout << "Usage: " << argv[0] << " [url]" << std::endl;
        return 1;
    }

    http::client client;
    http::client::request request(argv[1]);
    request << header("Connection", "close");
    http::client::response response = client.get(request);
    std::cout << body(response) << std::endl;

    return 0;
}

However, it fails with this error:

Error   C2446   ':': no conversion from 'boost::asio::error::netdb_errors' to 'const std::error_code'

I'm using VS2015, cpp-netlib 0.12.0 (final) and Boost 1.55.0, and I have no idea what could cause this. Is there a way to fix it? I've been scratching my head trying to get this library to work for a few days, but it seems a new error always has to come up unfortunately.

Upvotes: 1

Views: 828

Answers (2)

grobx
grobx

Reputation: 343

I'm using clang 7.3.0, cppnetlib 0.12.0, asio 1.10.6 and boost 10.60.0 on OS X 10.11.4 and it works.

I compiled the example you provided using clang++ -lcppnetlib-uri -lcppnetlib-client-connections -lssl -lcrypto -I/opt/local/include -L/opt/local/lib -std=c++11 test.cpp -o test.

Make sure to add #define BOOST_NETWORK_ENABLE_HTTPS before including boost/network/protocol/http/client.hpp if you want to enable HTTPS support.

Upvotes: 0

Xirema
Xirema

Reputation: 20396

In boost::asio, you're expected to use boost::system::error_code any time you intend to use error codes in your callbacks/invocations, not std::error_code.

I don't know what netlib is doing in the background, but this could be evidence of either a mistake in the reference code, or simply an older version of the code using the wrong symbols.

Upvotes: 0

Related Questions