Note that there are some explanatory texts on larger screens.

plurals
  1. POCode::Blocks and Boost Asio. It just wont work
    primarykey
    data
    text
    <p>I am having trouble getting Boost.Asio to compile in Code::Blocks. I installed and compiled Boost C++ Libraries and got both the given test examples to run. Now I am trying to get Boost.Asio to run.</p> <p>Here is the compiler call:</p> <p><code>mingw32-g++.exe -L"C:\Program Files (x86)\boost\boost_1_49_0" -o bin\Debug\server.exe obj\Debug\server.o D:\CodeBlocksIDE\CodeBlocks\lib\libboost_filesystem-mgw44-mt-1_49.a D:\CodeBlocksIDE\CodeBlocks\lib\libboost_system-mgw44-mt-1_49.a</code></p> <p>And here is the output (see <a href="http://imageshack.us/f/267/cdbideboost1.png/" rel="nofollow noreferrer">this</a> link for more):</p> <pre><code>boost/asio/detail/impl/winsock_init.ipp:39: undefined reference to 'WSAStartup@8' boost/asio/detail/impl/winsock_init.ipp:48: undefined reference to 'WSAStartup@0' boost/asio/detail/impl/socket_ops.ipps:50: undefined reference to 'WSASetLastError@4' boost/asio/detail/impl/socket_ops.ipps:178: undefined reference to 'GetAcceptExSockaddrs@32' boost/asio/detail/impl/socket_ops.ipps:296: undefined reference to 'closesocket@4' </code></pre> <p>Here is the code:</p> <pre><code>// // server.cpp // ~~~~~~~~~~ // // Copyright (c) 2003-2012 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #include &lt;cstdlib&gt; #include &lt;iostream&gt; #include &lt;boost/aligned_storage.hpp&gt; #include &lt;boost/array.hpp&gt; #include &lt;boost/bind.hpp&gt; #include &lt;boost/enable_shared_from_this.hpp&gt; #include &lt;boost/noncopyable.hpp&gt; #include &lt;boost/shared_ptr.hpp&gt; #include &lt;boost/asio.hpp&gt; using boost::asio::ip::tcp; // Class to manage the memory to be used for handler-based custom allocation. // It contains a single block of memory which may be returned for allocation // requests. If the memory is in use when an allocation request is made, the // allocator delegates allocation to the global heap. class handler_allocator : private boost::noncopyable { public: handler_allocator() : in_use_(false) { } void* allocate(std::size_t size) { if (!in_use_ &amp;&amp; size &lt; storage_.size) { in_use_ = true; return storage_.address(); } else { return ::operator new(size); } } void deallocate(void* pointer) { if (pointer == storage_.address()) { in_use_ = false; } else { ::operator delete(pointer); } } private: // Storage space used for handler-based custom memory allocation. boost::aligned_storage&lt;1024&gt; storage_; // Whether the handler-based custom allocation storage has been used. bool in_use_; }; // Wrapper class template for handler objects to allow handler memory // allocation to be customised. Calls to operator() are forwarded to the // encapsulated handler. template &lt;typename Handler&gt; class custom_alloc_handler { public: custom_alloc_handler(handler_allocator&amp; a, Handler h) : allocator_(a), handler_(h) { } template &lt;typename Arg1&gt; void operator()(Arg1 arg1) { handler_(arg1); } template &lt;typename Arg1, typename Arg2&gt; void operator()(Arg1 arg1, Arg2 arg2) { handler_(arg1, arg2); } friend void* asio_handler_allocate(std::size_t size, custom_alloc_handler&lt;Handler&gt;* this_handler) { return this_handler-&gt;allocator_.allocate(size); } friend void asio_handler_deallocate(void* pointer, std::size_t /*size*/, custom_alloc_handler&lt;Handler&gt;* this_handler) { this_handler-&gt;allocator_.deallocate(pointer); } private: handler_allocator&amp; allocator_; Handler handler_; }; // Helper function to wrap a handler object to add custom allocation. template &lt;typename Handler&gt; inline custom_alloc_handler&lt;Handler&gt; make_custom_alloc_handler( handler_allocator&amp; a, Handler h) { return custom_alloc_handler&lt;Handler&gt;(a, h); } class session : public boost::enable_shared_from_this&lt;session&gt; { public: session(boost::asio::io_service&amp; io_service) : socket_(io_service) { } tcp::socket&amp; socket() { return socket_; } void start() { socket_.async_read_some(boost::asio::buffer(data_), make_custom_alloc_handler(allocator_, boost::bind(&amp;session::handle_read, shared_from_this(), boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred))); } void handle_read(const boost::system::error_code&amp; error, size_t bytes_transferred) { if (!error) { boost::asio::async_write(socket_, boost::asio::buffer(data_, bytes_transferred), make_custom_alloc_handler(allocator_, boost::bind(&amp;session::handle_write, shared_from_this(), boost::asio::placeholders::error))); } } void handle_write(const boost::system::error_code&amp; error) { if (!error) { socket_.async_read_some(boost::asio::buffer(data_), make_custom_alloc_handler(allocator_, boost::bind(&amp;session::handle_read, shared_from_this(), boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred))); } } private: // The socket used to communicate with the client. tcp::socket socket_; // Buffer used to store data received from the client. boost::array&lt;char, 1024&gt; data_; // The allocator to use for handler-based custom memory allocation. handler_allocator allocator_; }; typedef boost::shared_ptr&lt;session&gt; session_ptr; class server { public: server(boost::asio::io_service&amp; io_service, short port) : io_service_(io_service), acceptor_(io_service, tcp::endpoint(tcp::v4(), port)) { session_ptr new_session(new session(io_service_)); acceptor_.async_accept(new_session-&gt;socket(), boost::bind(&amp;server::handle_accept, this, new_session, boost::asio::placeholders::error)); } void handle_accept(session_ptr new_session, const boost::system::error_code&amp; error) { if (!error) { new_session-&gt;start(); } new_session.reset(new session(io_service_)); acceptor_.async_accept(new_session-&gt;socket(), boost::bind(&amp;server::handle_accept, this, new_session, boost::asio::placeholders::error)); } private: boost::asio::io_service&amp; io_service_; tcp::acceptor acceptor_; }; int main(int argc, char* argv[]) { try { if (argc != 2) { std::cerr &lt;&lt; "Usage: server &lt;port&gt;\n"; return 1; } boost::asio::io_service io_service; using namespace std; // For atoi. server s(io_service, atoi(argv[1])); io_service.run(); } catch (std::exception&amp; e) { std::cerr &lt;&lt; "Exception: " &lt;&lt; e.what() &lt;&lt; "\n"; } return 0; } </code></pre> <p>Here are some images concerning my problem.</p> <p><a href="http://imageshack.us/f/267/cdbideboost1.png" rel="nofollow noreferrer">http://imageshack.us/f/267/cdbideboost1.png</a></p> <p> <p><a href="http://imageshack.us/f/833/cdbideboost3.png" rel="nofollow noreferrer">http://imageshack.us/f/833/cdbideboost3.png</a></p> <p><a href="http://imageshack.us/f/31/cdbideboost4.png" rel="nofollow noreferrer">http://imageshack.us/f/31/cdbideboost4.png</a></p> <p><a href="http://imageshack.us/f/525/cdbideboost5.png" rel="nofollow noreferrer">http://imageshack.us/f/525/cdbideboost5.png</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload