c++ - Compile asio with gcc -
i tried compile http server here http://think-async.com/asio/asio-1.11.0/doc/asio/examples/cpp11_examples.html#asio.examples.cpp11_examples.http_server gcc. used
g++ main.cpp -std=c++11 -i/home/gabi/downloads/asio-1.11.0/include -pthread i this
/tmp/cce1vizf.o: in function `http::server::server::server(std::string const&, std::string const&, std::string const&)': server.cpp:(.text+0x1a3): undefined reference `http::server::connection_manager::connection_manager()' server.cpp:(.text+0x1e0): undefined reference `http::server::request_handler::request_handler(std::string const&)' /tmp/cce1vizf.o: in function `http::server::server::do_accept()::{lambda(std::error_code)#1}::operator()(std::error_code) const': server.cpp:(.text+0x52a): undefined reference `http::server::connection_manager::start(std::shared_ptr<http::server::connection>)' /tmp/cce1vizf.o: in function `http::server::server::do_await_stop()::{lambda(std::error_code, int)#1}::operator()(std::error_code, int) const': server.cpp:(.text+0x5e9): undefined reference `http::server::connection_manager::stop_all()' /tmp/cce1vizf.o: in function `_zn9__gnu_cxx13new_allocatorin4http6server10connectionee9constructis3_in4asio19basic_stream_socketins6_2ip3tcpens6_21stream_socket_serviceis9_eeeerns2_18connection_managererns2_15request_handlereeeevpt_dpot0_': server.cpp:(.text._zn9__gnu_cxx13new_allocatorin4http6server10connectionee9constructis3_in4asio19basic_stream_socketins6_2ip3tcpens6_21stream_socket_serviceis9_eeeerns2_18connection_managererns2_15request_handlereeeevpt_dpot0_[_zn9__gnu_cxx13new_allocatorin4http6server10connectionee9constructis3_in4asio19basic_stream_socketins6_2ip3tcpens6_21stream_socket_serviceis9_eeeerns2_18connection_managererns2_15request_handlereeeevpt_dpot0_]+0x8b): undefined reference `http::server::connection::connection(asio::basic_stream_socket<asio::ip::tcp, asio::stream_socket_service<asio::ip::tcp> >, http::server::connection_manager&, http::server::request_handler&)' collect2: error: ld returned 1 exit status does know why? if try compile http://think-async.com/asio/asio-1.11.0/doc/asio/examples/cpp11_examples.html#asio.examples.cpp11_examples.allocation works.
first off, let me seems have provided wrong compilation command produce error message, since error message indicates you're compiling server.cpp, e.g.:
server.cpp:(.text+0x1a3): undefined reference 'http::server::connection_manager::connection_manager()' when you're not. in fact, you're compiling main.cpp, since that's cpp file that's in compilation command gave.
as answer states, need compile all of .cpp files http server, not main.cpp. that, pass of .cpp files g++ command:
g++ main.cpp connection.cpp connection_manager.cpp mime_types.cpp reply.cpp request_handler.cpp request_parser.cpp server.cpp -std=c++11 -i/home/gabi/downloads/asio-1.11.0/include -pthread and finally, contrary answer says, not need link against libraries, because asio header-only library. boost.asio, however, not header-only, , if using boost.asio, you'd need link boost 'system' library following linker flags:
-l/path/to/folder/containing/boost/libs/ -lboost_system
(this assuming boost libraries not installed in standard system location, such /lib; if were, omit -l flag. stated in comment, -lboost_system tells linker (ld) library called libboost_system.so. see ld man page more information on how ld finds libraries.)
however, since, said, using asio , not boost.asio, fine including appropriate .hpp header files , using -i compiler flag point header file locations.
Comments
Post a Comment