2013-02-21 80 views
0

我試圖使用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的幫助

回答

2

快速谷歌搜索顯示,AIX已與重載決議的問題,尤其是當涉及模板。因此,可能值得嘗試不同的方法來減少需要發生的過載分辨率。

例如,可以使用boost::mem_fn()來代替boost::bind()

std::size_t (io_service::*run)() = &io_service::run; 
boost::thread t(boost::mem_fn(run), io_service); 

此外,如果編譯器仍然有問題解決重載,那麼考慮編寫一個簡單的函子。 boost::thread()構造函數的唯一要求是func參數是可複製的,並且func()必須是有效的表達式。

struct service_runner 
{ 
    explicit service_runner(boost::shared_ptr<boost::asio::io_service> io_service) 
    : io_service(io_service) 
    {} 
    std::size_t operator()() { return io_service->run(); } 
    boost::shared_ptr<boost::asio::io_service> io_service; 
}; 

... 

boost::thread t((service_runner(io_service))); 

其他需要考慮:

  • 身高符合編譯代碼,而不是使用編譯器標誌,讓不合格的代碼進行編譯。在這種特殊情況下,io_service::run()是一個非const成員函數,但綁定到它的accept_io_service實例參數通過boost::cref()作爲常量引用傳遞。需要添加編譯器標誌,例如gcc的-fpermissive,以允許編譯不合格的代碼。在使用這些選項時要非常小心,因爲它們可能會掩蓋嚴重的問題。
  • 考慮將boost::shared_ptr作爲綁定調用的實例句柄。只要線程仍在運行,這將使io_service保持活動狀態。否則,io_service可能會在線程仍在處理其事件循環時被刪除,從而導致調用未定義行爲的高可能性。
+0

非常感謝你的服務亞軍包裹,它的工作就像一個魅力。第一種使用'boost :: mem_fn()'的方法沒有找到原因'限定符「accept_io_service_」沒有在當前範圍中定義,這是奇怪的,因爲它是一個成員變量。要評論其他觀點,'boost :: cref()'只是我在論壇上發現的一個測試,在其他平臺上我正在使用'boost :: shared_ptr'。再次感謝您提供了很好的建議。 – Pinker 2013-02-22 12:22:25

+0

還有一個問題,在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

+0

@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

1

只是好奇,你正在使用IBM boost庫修補程序爲您正在使用的編譯器? http://www-01.ibm.com/support/docview.wss?uid=swg27006911

+0

從3年前的日期開始,使用提升1.40。0(這是13次發佈),我預計這些解決方案中的大多數已經在boost庫中,並且也預計在這13個版本中修復了很多bug(即使Im使用boost爲1.49.0) – Pinker 2013-02-26 08:07:39

+0

Pinker,恕我直言,你太樂觀了。我更願意檢查每個版本,我自己運行增強迴歸測試。 – vond 2013-03-10 18:46:59

0

看的4個可能的候選者嘗試的消息,差異似乎是由於您使用的是V11常量相關

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 
>)". 
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>)". 
No candidate is better than "boost::bind<unsigned long,boost::asio::io_service,boost::asio::io_service *>(unsigned long (io_service::*)() const, io_service *)". 
No candidate is better than "boost::bind<unsigned long,boost::asio::io_service,boost::asio::io_service *>(unsigned long (io_service::*)(), io_service *)". 

。1個編譯器,有一對夫婦的修復不是默認啓用的,你可以嘗試使用下面的選項

-qxflag = EnableIssue214PartialOrdering 這將使有關C++核心語言問題了一些修復214

-qxflag = FunctionCVTmplArgDeduction2011 這使得一些C++ 2011點的澄清,以參數推導

這些變化都在V12.1編譯器默認設置,但不是在V11.1編譯器

0

我加入additinal響應,如果有人跌倒ü一般來說這個問題。 因爲我發現這與編譯器無法解析使用哪個函數有關,如果函數具有相同的名稱但參數不同。

實施例:

void test(int a); 
void test(int a, int b); 

不工作,並且將導致類似的錯誤如上。
但改變這樣的名字:

void test(int a); 
void test2(int a, int b); 

...會完全正常工作。

與創建包裝器相比,這絕對不是開銷解決方案(正如我自己一直在觀察這個過程一樣)。

希望有人會發現這有用。

相關問題