0

我尝试使用 boost 编译项目,将 asio::io_service 绑定到 boost::thread,并且我遇到了我不知道如何解决的错误使用:IBM XL C/C++ for AIX,V11.1 (5724-X13),版本: 11.01.0000.0006 (AIX 7.1)

    "/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) 上编译得非常好。

谢谢帮助

4

4 回答 4

2

快速的 google 搜索表明 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()是一个非常量成员函数,但accept_io_service绑定到它的实例参数作为常量引用通过boost::cref(). 需要添加编译器标志,例如 gcc's-fpermissive以允许编译不合格代码。使用这些选项时要非常小心,因为它们可能会掩盖严重的问题。
  • 考虑boost::shared_ptr作为实例句柄传递给绑定调用。io_service只要线程仍在运行,这将保持活动状态。否则,io_service可能会在线程仍在处理其事件循环时被删除,从而导致调用未定义行为的可能性很高。
于 2013-02-21T16:30:21.693 回答
1

只是好奇,您是否为您正在使用的编译器使用 IBM boost 库补丁?http://www-01.ibm.com/support/docview.wss?uid=swg27006911

于 2013-02-25T16:41:30.263 回答
0

查看尝试的 4 个可能的候选人的消息,差异似乎与 const 相关

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 *)".

由于您使用的是 V11.1 编译器,因此默认情况下未启用一些修复,您可以尝试使用以下选项

-qxflag=EnableIssue214PartialOrdering 这将启用与 C++ 核心语言问题 214 相关的几个修复

-qxflag=FunctionCVTmplArgDeduction2011 这启用了一些 C++2011 对参数推导的澄清

这些更改是 V12.1 编译器的默认值,但不是 V11.1 编译器的默认值

于 2013-02-25T16:59:34.773 回答
0

如果有人偶然发现这个问题,我会添加额外的响应。因为我发现这与编译器无法解析使用哪个函数有关,如果函数名称相同,但参数不同。

例子:

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

将不起作用,并且会导致与上述类似的错误。
但是像这样更改名称:

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

...会很好地工作。

这绝对是比创建包装器更少的开销解决方案(正如我自己在观察到这一点之前所做的那样)。

希望有人会发现这很有用。

于 2014-07-28T11:47:55.387 回答