Note that there are some explanatory texts on larger screens.

plurals
  1. POCompilation error when including boost/thread.cpp
    primarykey
    data
    text
    <p>I have the following code using Boost ASIO to setup a TCP client. Here is my code adapted from the Boost doc's <a href="http://www.boost.org/doc/libs/1_50_0/doc/html/boost_asio/example/chat/chat_client.cpp" rel="nofollow">chat example</a>.</p> <pre><code>class AsioCommunicationService { AsioCommunicationService::AsioCommunicationService( boost::asio::io_service&amp; io_service, tcp::resolver::iterator endpoint_iterator) : io_service_(io_service), socket_(io_service) { tcp::endpoint endpoint = *endpoint_iterator; socket_.async_connect(endpoint, boost::bind(&amp;AsioCommunicationService::handle_connect, this, boost::asio::placeholders::error, ++endpoint_iterator)); } void AsioCommunicationService::handle_connect(const boost::system::error_code&amp; error, tcp::resolver::iterator endpoint_iterator) { if (!error) { boost::asio::async_read(socket_, boost::asio::buffer(read_msg_.data(), LampMessage::header_length), boost::bind(&amp;AsioCommunicationService::handle_read_header, this, boost::asio::placeholders::error)); } } } class Connection { //init io_service, query, resolve, iterator here boost::asio::io_service io_service; boost::asio::ip::tcp::resolver resolver(io_service); boost::asio::ip::tcp::resolver::query query(host, service); boost::asio::ip::tcp::resolver::iterator endpoint_iterator = resolver.resolve(query); m_session = std::shared_ptr&lt;AsioCommunicationService&gt;( new AsioCommunicationService(io_service, iterator)); //start new thread for io_service.run --&gt; GOT AN ERROR when include boost/thread.hpp boost::thread t(boost::bind(&amp;boost::asio::io_service::run, &amp;io_service)); //this synchronous command would work, but it's blocking the program. I don't want that. //io_service.run(); } </code></pre> <p>Of course, I needed to include boost/thread to make the declaration to variable t in class Connection works. But when I did so, I got this error</p> <pre><code>#include &lt;boost/thread.hpp&gt; //ERROR: In function ‘boost::thread&amp;&amp; boost::move(boost::thread&amp;&amp;)’: ///usr/include/boost/thread/detail/thread.hpp:349:16: error: invalid initialization of reference of type ‘boost::thread&amp;&amp;’ from expression of type ‘boost::thread’ //In file included from /usr/include/boost/thread/detail/thread_heap_alloc.hpp:17:0, // from /usr/include/boost/thread/detail/thread.hpp:13, // from /usr/include/boost/thread/thread.hpp:22, // from /usr/include/boost/thread.hpp:13, // from /home/son/dev/logistics/src/frameworks/networkService/NetworkConnection.cpp:13: ///usr/include/boost/thread/pthread/thread_heap_alloc.hpp: In function ‘T* boost::detail::heap_new(A1&amp;&amp;) [with T = boost::detail::thread_data&lt;void (*)()&gt;, A1 = void (*&amp;)()]’: ///usr/include/boost/thread/detail/thread.hpp:130:95: instantiated from here ///usr/include/boost/thread/pthread/thread_heap_alloc.hpp:24:47: error: cannot bind ‘void (*)()’ lvalue to ‘void (*&amp;&amp;)()’ ///usr/include/boost/thread/detail/thread.hpp:43:13: error: initializing argument 1 of ‘boost::detail::thread_data&lt;F&gt;::thread_data(F&amp;&amp;) [with F = void (*)()]’ </code></pre> <p>It would compile and work if I remove the include to boost/thread.hpp, and replace the declaration to t by a simple call to io_service.run(); I'm wondering if this compilation error has to do with boost version. I'm using Boost ASIO 1.42, Ubuntu 11.04 and Eclipse if those are of any help. Thank you in advance.</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.
    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