-1

Here is a piece of code which is an example from cpp-netlib

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

namespace http = boost::network::http;

struct hello_world;
typedef http::server<hello_world> server;

struct hello_world {
    void operator() (server::request const &request,
                     server::response &response) {
        std::string ip = source(request);
        response = server::response::stock_reply(
            server::response::ok, std::string("Hello, ") + ip + "!");
    }
};

int
main(int argc, char * argv[]) {

    if (argc != 3) {
        std::cerr << "Usage: " << argv[0] << " address port" << std::endl;
        return 1;
    }

    try {
        hello_world handler;
        server server_(argv[1], argv[2], handler);
        server_.run();
    }
    catch (std::exception &e) {
        std::cerr << e.what() << std::endl;
        return 1;
    }

    return 0;
}

But on compiling that is g++ main.cpp -o socke.exe -lboost_system I get the following errors

main.cpp:1:50: error: boost/network/protocol/http/server.hpp: No such file or directory
main.cpp:5: error: âboostâ has not been declared

I have installed the cpnet-lib libraries and cmake for build them. I cant get to understand why couldnt the compiler find the libraries.

7
  • Did you install boost libraries also? Commented Apr 15, 2015 at 8:05
  • yes boost_1_56_0.7 is installed. Commented Apr 15, 2015 at 8:06
  • Is it boost lib path updated in LIBPATH? Commented Apr 15, 2015 at 8:07
  • Yes it is export PATH=$PATH:/usr/local/include/:/usr/local/lib/ The problem is i cant find the file my self when i locate it on the system Commented Apr 15, 2015 at 8:08
  • There is another env variable called LIBPATH please update that one. It is not PATH. Commented Apr 15, 2015 at 8:11

1 Answer 1

2

You didn't specify include path where Boost and cpp-netlib headers are located. The first error line tells which header is missing. Assuming your Boost headers are installed under /a/my_boost (i.e. there is a /a/my_boost/boost subdirectory with headers) and cpp-netlib under /a/my_cpp-netlib, you need to add -I command line options for your compiler:

g++ main.cpp -o socke.exe -I/a/my_boost -I/a/my_cpp-netlib -lboost_system

If you're using a graphical IDE or a build system, there should be an option in the project settings to add include directories.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.