0

So my current code I am trying to compile:

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

int main()
{
    boost::network::http::client client;

    boost::network::http::client::request request("http://www.example.com");
    request << boost::network::header("Connection", "close");
    boost::network::http::client::response response = client.get(request);

    std::cout << body(response);

    return 0;
}

All code harvested from [this post] (How can I fetch data from a website inside a C++ program). So I've tried running this thing by itself with a few different scripts provided, but none have worked. Here are some of the scripts I've tried:

g++ -I. -I$BOOST_ROOT -L$BOOST_ROOT/stage/lib -lboost_system
g++ -I. -I/usr/local/include/boost -lboost_thread -lboost_system
-lcppnetlib -client -connections -lcppnetlib -server -parsers
-lcppnetlib -uri -pthread main.cpp
./a.out

I have also tried:

g++ -I. -I$BOOST_ROOT -L$BOOST_ROOT/stage/lib -lboost_system -pthread main.cpp

And also tried:

g++ -I. -I/usr/local/Cellar/boost/1.59.0/include/boost -L/usr/local/Cellar/boost/1.59.0/lib -lboost_system pthread main.cpp

But I noticed after reading some more posts that the -I is used to signify the header files for boost in their root directory and the -L is used to find the libraries for the boost root directory. So I am not sure exactly what I've downloaded because I now have 2 copies and I am not sure if either of them work, and I am tried every combination to try to get this thing running. Apparently I have several copies of boost sitting all over the place. So the /usr/local/Cellar directory holds both up to date ones..

/usr/local/Cellar/boost/1.59.0/include/boost

/usr/local/Cellar/boost/1.59.0/include/lib

Also, the /usr/local/ directory holds both..

/usr/local/include/boost/

/usr/local/lib

And again,

/usr/local/opt/boost/include

/usr/local/opt/boost/include/lib

Does having multiple copies disrupt the process or something? I am so confused.

This is my directory structure:
directory structure

So my I've tried figuring this out and I am simply stumped.. I am not good with scripting (just recently learned most of it from this issue), and I simply do not know how to compile this thing.. Any help is any way, shape, or form is beyond appreciated. Thanks in advance to anyone who helps.

Community
  • 1
  • 1
bmc
  • 817
  • 1
  • 12
  • 23
  • Whatever the library you're using is, it surely is _not_ part of Boost... – ildjarn Jan 12 '16 at 20:37
  • Such great insight. My question for you is 'then which library _should_ be included to properly work with boost?' – bmc Jan 12 '16 at 21:26
  • If you're looking for the proposed and subsequently rejected Boost.Http library, that can be found [here](https://github.com/BoostGSoC14/boost.http). The only official Boost library that deals with networking is [Boost.Asio](http://www.boost.org/libs/asio/). Note that Boost.Http was rejected as an official Boost library, but it is still being actively worked on. The code you've shown appears to be for cpp-netlib, which can be found [here](http://cpp-netlib.org/), and again is not an official Boost library. – ildjarn Jan 12 '16 at 21:33
  • Would you recommend using boost.asio over cpp-netlib? – bmc Jan 12 '16 at 21:46
  • cpp-netlib is a high-level abstraction built on top of Boost.Asio; i.e. they serve different purposes, and Asio is the lower-level of the two. Use whichever suits your needs best. – ildjarn Jan 12 '16 at 21:56

1 Answers1

1

Example was provided for cpp-netlib, which is not part of Boost C++.

But it can be built and installed as addition to your Boost installation as described in README.

Sergei Nikulov
  • 5,029
  • 23
  • 36