1

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.

grobx
  • 343
  • 6
  • 13
Spook
  • 301
  • 4
  • 9
  • Normally for `boost asio` you must link with `boost_system` to handle errors. However, I've had a quick look through `boost/asio/error.hpp` and `boost/system/error_code.hpp`, I don't think that `boost::asio::error::netdb_errors` is an `asio` error, I think it's a `cpp-netlib` error... Hopefully, they've used the same mechanism. – kenba May 03 '16 at 06:50

2 Answers2

0

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.

Xirema
  • 19,889
  • 4
  • 32
  • 68
0

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.

grobx
  • 343
  • 6
  • 13