我試圖使用boost編譯項目,將asio :: io_service綁定到boost :: thread,並且我得到了我不知道如何解決的錯誤 使用:IBM XL C/C++ for AIX, V11.1(5724-X13),版本:11.01.0000.0006(AIX 7.1),是造成錯誤Boost綁定AIX xlc io_service運行
"/home/clag/projects/tomas/include/boost/asio/detail/posix_fd_set_adapter.hpp", line 33.30: 1540-0198 (W) The omitted keyword "private" is assumed for base class "noncopyable".
"/home/clag/projects/tomas/ots/src/agent/agent.cc", line 50.46: 1540-0219 (S) The call to "boost::bind" has no best match.
"/home/clag/projects/tomas/ots/src/agent/agent.cc", line 50.58: 1540-1229 (I) Argument number 1 is an rvalue of type "overloaded function: boost::asio::io_service::run".
"/home/clag/projects/tomas/ots/src/agent/agent.cc", line 50.100: 1540-1229 (I) Argument number 2 is an rvalue of type "const boost::reference_wrapper<const boost::asio::io_service>".
"/home/clag/projects/tomas/include/boost/bind/bind_mf_cc.hpp", line 30.5: 1540-1202 (I) No candidate is better than "boost::bind<unsigned long,boost::asio::io_service,boost::reference_wrapper<const boost::asio::io_service> >(unsigned long (io_service::*)() const, reference_wrapper<const boost::asio::io_service>)".
"/home/clag/projects/tomas/ots/src/agent/agent.cc", line 50.58: 1540-1231 (I) The conversion from argument number 1 to "unsigned long (boost::asio::io_service::*)() const" uses the resolved overloaded function "size_t boost::asio::io_service::run()".
"/home/clag/projects/tomas/ots/src/agent/agent.cc", line 50.100: 1540-1231 (I) The conversion from argument number 2 to "boost::reference_wrapper<const boost::asio::io_service>" uses "the identity conversion".
"/home/clag/projects/tomas/include/boost/bind/bind_mf_cc.hpp", line 20.5: 1540-1202 (I) No candidate is better than "boost::bind<unsigned long,boost::asio::io_service,boost::reference_wrapper<const boost::asio::io_service> >(unsigned long (io_service::*)(), reference_wrapper<const boost::asio::io_service>)".
"/home/clag/projects/tomas/ots/src/agent/agent.cc", line 50.58: 1540-1231 (I) The conversion from argument number 1 to "unsigned long (boost::asio::io_service::*)()" uses the resolved overloaded function "size_t boost::asio::io_service::run()".
"/home/clag/projects/tomas/ots/src/agent/agent.cc", line 50.100: 1540-1231 (I) The conversion from argument number 2 to "boost::reference_wrapper<const boost::asio::io_service>" uses "the identity conversion".
"/home/clag/projects/tomas/ots/src/agent/agent.cc", line 52.35: 1540-0219 (S) The call to "boost::bind" has no best match.
"/home/clag/projects/tomas/ots/src/agent/agent.cc", line 52.47: 1540-1229 (I) Argument number 1 is an rvalue of type "overloaded function: boost::asio::io_service::run".
"/home/clag/projects/tomas/ots/src/agent/agent.cc", line 52.98: 1540-1229 (I) Argument number 2 is an rvalue of type "boost::asio::io_service *".
"/home/clag/projects/tomas/include/boost/bind/bind_mf_cc.hpp", line 30.5: 1540-1202 (I) No candidate is better than "boost::bind<unsigned long,boost::asio::io_service,boost::asio::io_service *>(unsigned long (io_service::*)() const, io_service *)".
"/home/clag/projects/tomas/ots/src/agent/agent.cc", line 52.47: 1540-1231 (I) The conversion from argument number 1 to "unsigned long (boost::asio::io_service::*)() const" uses the resolved overloaded function "size_t boost::asio::io_service::run()".
"/home/clag/projects/tomas/ots/src/agent/agent.cc", line 52.98: 1540-1231 (I) The conversion from argument number 2 to "boost::asio::io_service *" uses "the identity conversion".
"/home/clag/projects/tomas/include/boost/bind/bind_mf_cc.hpp", line 20.5: 1540-1202 (I) No candidate is better than "boost::bind<unsigned long,boost::asio::io_service,boost::asio::io_service *>(unsigned long (io_service::*)(), io_service *)".
"/home/clag/projects/tomas/ots/src/agent/agent.cc", line 52.47: 1540-1231 (I) The conversion from argument number 1 to "unsigned long (boost::asio::io_service::*)()" uses the resolved overloaded function "size_t boost::asio::io_service::run()".
"/home/clag/projects/tomas/ots/src/agent/agent.cc", line 52.98: 1540-1231 (I) The conversion from argument number 2 to "boost::asio::io_service *" uses "the identity conversion".
"/home/clag/projects/tomas/include/boost/asio/impl/write.hpp", line 276.7: 1540-0198 (W) The omitted keyword "private" is assumed for base class "detail::base_from_completion_cond<CompletionCondition>".
"/home/clag/projects/tomas/include/boost/asio/impl/write.hpp", line 276.7: 1540-0198 (W) The omitted keyword "private" is assumed for base class "detail::base_from_completion_cond>boost::asio::detail::transfer_all_t>"
代碼:
acceptor_thread_.reset(new boost::thread(boost::bind(&boost::asio::io_service::run, boost::cref(*accept_io_service_))));
for (int i = 0; i < agent_config_.threads(); i++) {
thread_group_.create_thread(boost::bind(&boost::asio::io_service::run, work_io_service_.get()));
}
定義:
boost::shared_ptr<boost::asio::io_service> accept_io_service_;
boost::shared_ptr<boost::thread> acceptor_thread_;
boost::shared_ptr<boost::asio::io_service> work_io_service_;
boost::thread_group thread_group_;
只需提一下,這可能只是一些標誌選項,但我無法在任何地方找到它 因爲相同的代碼在Linux(GCC),HP-UX(aCC)和Windows(MSVC)上編譯完美。
THX的幫助
非常感謝你的服務亞軍包裹,它的工作就像一個魅力。第一種使用'boost :: mem_fn()'的方法沒有找到原因'限定符「accept_io_service_」沒有在當前範圍中定義,這是奇怪的,因爲它是一個成員變量。要評論其他觀點,'boost :: cref()'只是我在論壇上發現的一個測試,在其他平臺上我正在使用'boost :: shared_ptr'。再次感謝您提供了很好的建議。 – Pinker 2013-02-22 12:22:25
還有一個問題,在AIX 6.1(xlC_r V9.0)上它不能編譯,我得到了'/include/boost/thread/detail/thread.hpp',第62.17行:1540-0204(S)一個類型爲「 boost :: thread *「一定不能跟在使用'service_runner'的函數調用operator().'錯誤之後,你能解釋一下我使用'mem_fn'的更好的解決方案嗎?因爲我沒有真正理解'std :: size_t (io_service :: * run)()=&io_service :: run;'statement。謝謝 – Pinker 2013-03-04 07:40:14
@Pinker:由於我對AIX不熟悉,因此必須查看用法才能確定問題。聲明'run'作爲指向'io_service'成員函數的指針,返回'std :: size_t'並且不接受任何參數,然後將'io_service :: run()'的地址賦給成員函數指針。目標是明確的,防止編譯器必須在重載['io_service :: run()']的'bind'調用中推斷簽名(http://www.boost.org/doc/lib S/1_53_0/DOC/HTML/boost_asio /參考/ io_service對象/ run.html)。 – 2013-03-05 13:49:43