2017-06-17 5 views
0

私は、cpp-netlib.orgでhello worldの例をcpp-netlib-0.12.0とboost-1.64.0を使ってUbuntu 16.04で実行しようとしました。コードの一部は、(1行目から)である。cpp-netlibこんにちはワールドの例がLinuxでコンパイルされない

test1.cpp:11:61: error: ‘boost::network::http::server<hello_world>::response’ has not been declared 
    void operator()(server::request const &request, server::response &response) 
                  ^
test1.cpp: In member function ‘void hello_world::operator()(const request&, int&)’: 
test1.cpp:17:28: error: ‘boost::network::http::server<hello_world>::response’ has not been declared 
     response = server::response::stock_reply(server::response::ok, data.str()); 
          ^
test1.cpp:17:58: error: ‘boost::network::http::server<hello_world>::response’ has not been declared 
     response = server::response::stock_reply(server::response::ok, data.str()); 
                 ^

I:私は次のエラーを取得する

g++ test1.cpp -o test1 -std=c++11 -lcppnetlib-uri -lcppnetlib-server-parsers -lcppnetlib-client-connections -lboost_system -lboost_thread -lpthread 

を:

#include <boost/network/protocol/http/server.hpp> 
#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) 
    { 
     server::string_type ip = source(request); 
     unsigned int port = request.source_port; 
     std::ostringstream data; 
     data << "Hello, " << ip << ':' << port << '!'; 
     response = server::response::stock_reply(server::response::ok, data.str()); 
    } 
    void log(const server::string_type& message) 
    { 
     std::cerr << "ERROR: " << message << std::endl; 
    } 
}; 

と私はコンパイルするために、次の行を使用する場合そのコードをウェブサイトの例から抜粋したものです。私はインクルードパスをチェックし、必要なライブラリはすべてそこにあるように見えます。私は問題が何であるか把握できないようです。

答えて

0

これはcpp-netlibのドキュメントがすべて乱されているようです(一般的なプロジェクト全体のように)。 HTTP server API pageは、(それが示唆するものの間違っ含める)http::serverためHandlerテンプレートパラメータが2番目のパラメータとしてconnection_ptrを取っメンバーoperator()を持つべきであると主張している:

#include <boost/network/protocol/http/server.hpp> 
#include <boost/network/utils/thread_pool.hpp> 

struct handler_type; 
typedef boost::network::http::server<handler_type> http_server; 

struct handler_type 
{ 
    void 
    operator() 
    (
     http_server::request const & request, 
     http_server::connection_ptr connection 
    ) 
    { 
     // do something here 
    } 
}; 
関連する問題