c++ - The sample code I got from cpp-netlib won't compile -
// copyright 2009 (c) tarro, inc. // copyright 2009 (c) dean michael berris <mikhailberis@gmail.com> // distributed under boost software license, version 1.0. // (see accompanying file license_1_0.txt or copy @ // http://www.boost.org/license_1_0.txt) // //[ hello_world_server_main /*` part of 'hello world' example. it's used demonstrate how easy set http server. in example create request handler , run server. */ #include <boost/network/protocol/http/server.hpp> #include <iostream> namespace http = boost::network::http; /*<< defines server. >>*/ struct hello_world; typedef http::server<hello_world> server; /*<< defines request handler. it's class defines 2 functions, `operator()` , `log()` >>*/ struct hello_world { /*<< function handles incoming request. >>*/ void operator() (server::request const &request, server::response &response) { server::string_type ip = source(request); std::ostringstream data; data << "hello, " << ip << "!"; response = server::response::stock_reply( server::response::ok, data.str()); } /*<< it's necessary define log function, it's ignored in example. >>*/ void log(...) { // nothing } }; int main(int argc, char * argv[]) { if (argc != 3) { std::cerr << "usage: " << argv[0] << " address port" << std::endl; return 1; } try { /*<< creates request handler. >>*/ hello_world handler; /*<< creates server. >>*/ server server_(argv[1], argv[2], handler); /*<< runs server. >>*/ server_.run(); } catch (std::exception &e) { std::cerr << e.what() << std::endl; return 1; } return 0; } //]
i suspect it's not linking libraries correctly. error when run make. can run example fine off cpp-netlib folder when try copy code , put in own folder, doesn't compile.
/home/stanley/cmpt373/textadventure/tools/simple_server_test/simpleservertest.cpp: in function ‘int main(int, char**)’: /home/stanley/cmpt373/textadventure/tools/simple_server_test/simpleservertest.cpp:56:49: error: no matching function call ‘boost::network::http::server<hello_world>::server(char*&, char*&, hello_world&)’ server server_(argv[1], argv[2], handler); ^ /home/stanley/cmpt373/textadventure/tools/simple_server_test/simpleservertest.cpp:56:49: note: candidate is: in file included /home/stanley/cmpt373/textadventure/tools/simple_server_test/simpleservertest.cpp:14:0: /home/stanley/cmpt373/textadventure/include/boost/network/protocol/http/server.hpp:44:12: note: boost::network::http::server<handler>::server(const options&) [with handler = hello_world; boost::network::http::server<handler>::options = boost::network::http::server_options<boost::network::http::tags::http_server, hello_world>] explicit server(options const &options) : server_base(options) {} ^ /home/stanley/cmpt373/textadventure/include/boost/network/protocol/http/server.hpp:44:12: note: candidate expects 1 argument, 3 provided make[2]: *** [tools/simple_server_test/cmakefiles/simpleservertest.dir/simpleservertest.cpp.o] error 1 make[1]: *** [tools/simple_server_test/cmakefiles/simpleservertest.dir/all] error 2 make: *** [all] error 2
note in cmakelists.txt under root directory, there 1 line asio
include_directories(deps/asio/asio/include)
add project, work
Comments
Post a Comment